首页 > 解决方案 > 在 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 平台来检查这个。

标签: c#.netwindows

解决方案


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

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

推荐阅读