如何在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#
运行此命令答案 0 :(得分:2)
如果您想开始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);
}