Reputation: 33
How can I run this command in c#
telalertc -i bilal -m "Test Message"
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);
How can I run this command using console application C#
Upvotes: 2
Views: 97
Reputation: 186668
If you want to start telalertc
start it, not 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);
}
Upvotes: 2