C# 通过运行命令cmd

C# 通过运行命令cmd,c#,.net,cmd,C#,.net,Cmd,如何在c#中运行此命令 telalertc-i bilal-m“测试消息” 如果要启动telalertc而不是cmd,如何使用控制台应用程序C运行此命令: System.Diagnostics.ProcessStartInfo procStartInfo = new ProcessStartInfo() { FileName = "telalertc", Arguments = " -i bilal -m \"Test Message\"", RedirectStan

如何在c#中运行此命令

telalertc-i bilal-m“测试消息”


如果要启动
telalertc
而不是
cmd
,如何使用控制台应用程序C运行此命令:

  System.Diagnostics.ProcessStartInfo procStartInfo = new ProcessStartInfo() {
    FileName = "telalertc",
    Arguments = " -i bilal -m \"Test Message\"",
    RedirectStandardOutput = true,
    UseShellExecute = false,
    CreateNoWindow = true,
    Domain = "*.*.*.*" // do you really want this?
  };

  // Wrap IDisposable into using
  using (var proc = System.Diagnostics.Process.Start(procStartInfo)) {
    // First wait for completeness  
    proc.WaitForExit();
    // Then read results
    string result = proc.StandardOutput.ReadToEnd();
    Console.WriteLine(result);
  }

为什么要直接运行
cmd
而不是
telalertc
?您可能无权运行exe,或者exe本身无权访问某些资源(例如
bilal
)@bilal-Ahmed:您可能想使用
重定向标准错误
来检查来自exeDone的邮件谢谢(Y)
  System.Diagnostics.ProcessStartInfo procStartInfo = new ProcessStartInfo() {
    FileName = "telalertc",
    Arguments = " -i bilal -m \"Test Message\"",
    RedirectStandardOutput = true,
    UseShellExecute = false,
    CreateNoWindow = true,
    Domain = "*.*.*.*" // do you really want this?
  };

  // Wrap IDisposable into using
  using (var proc = System.Diagnostics.Process.Start(procStartInfo)) {
    // First wait for completeness  
    proc.WaitForExit();
    // Then read results
    string result = proc.StandardOutput.ReadToEnd();
    Console.WriteLine(result);
  }