c# - 在 Windows 中执行 lsnrctl 命令的程序?
问题描述
我想在 Windows 平台上通过 C# 程序执行 lsnrctl status 命令。如果我使用该程序运行以获得结果,它将不会给出结果。
static void Main(string[] args)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
// the cmd program
startInfo.FileName = "cmd.exe";
// set my arguments. date is just a dummy example. the real work isn't use date.
startInfo.Arguments = "/c date";
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
// capture what is generated in command prompt
var output = process.StandardOutput.ReadToEnd();
// write output to console
Console.WriteLine(output);
process.WaitForExit();
Console.Read();
}
如何检查 Windows 平台上的侦听器状态
从 Windows oracle 安装目录提示 lsnrctl.exe。一旦 lsnrctl.exe 在 Windows 系统上运行。我可以通过键入侦听器名称来检查侦听器的状态。LSNRCTL> 状态
它将给出默认侦听器的状态。
同样,我可以从提示中检查任意数量的侦听器状态的状态。我想通过 C# 程序 windows 平台来检查这个。
解决方案
你是如此接近。不幸的是,您的命令date
正在等待您输入新日期。如果您更改该行,如下所示,您的代码应该可以正常工作:
startInfo.Arguments = "/c date /T"; // slash T means: just output the date
推荐阅读
- windows - React Native 应用程序是否能够在 Windows 服务器上运行?
- arrays - Excel 数组填充了 listobject 列范围的非空白值
- sql-server - DBCC 命令是存储过程还是函数?
- 3d - 在 python 中从 2D 图像的 z 堆栈制作 3D 模型
- sql - Postgres - 如何在表结构查询中检索默认值
- python-3.x - 如何在 AWS 中使用 S3 数据运行 python 脚本
- react-redux - 使用“redux-thunk”实现“useDispatch”钩子的问题
- python - 使用模式中的 ascii 数字打印每个字母
- python - 在字符串中添加 2 个十进制数字,保持精度
- python - 使用 django-channels/websocket 更新实时位置的有效方法