gpt4 book ai didi

c# - 通过运行命令cmd

转载 作者:行者123 更新时间:2023-11-30 23:05:22 26 4
gpt4 key购买 nike

如何在 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);

如何使用控制台应用程序 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);
}

关于c# - 通过运行命令cmd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48884839/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com