在Windows中执行lsnrctl命令的程序?

时间:2018-04-26 16:17:48

标签: c# .net windows

我想在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#program windows platform来解决这个问题。

1 个答案:

答案 0 :(得分:1)

你太近了。不幸的是,您的命令date正在等待您输入新的日期。如果您更改该行,如下所示,您的代码应该可以正常工作:

startInfo.Arguments = "/c date /T";  // slash T means: just output the date
相关问题