我如何在C#中运行此命令
telalertc -i bilal -m“测试消息”
string command = "telalertc -i bilal -m "Test";
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", " /c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
procStartInfo.Domain = "*.*.*.*";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
Console.WriteLine(result);
如何使用控制台应用程序C#运行此命令
最佳答案
如果要启动telalertc
而不是cmd
,请启动它:
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);
}