我正在开发一个Windows应用程序。我正在调用命令提示符,我需要调用exe文件来获取exe文件参数。
我可以打开命令提示符但无法发送参数
string strCmdText = "create-keyfile.exe ..\\KatanaFirmware\\key-template.txt ..\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
请帮帮我。
由于
Punith
答案 0 :(得分:4)
System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo("create-keyfile.exe");
startInfo.Arguments = "..\\KatanaFirmware\\key-template.txt ..\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
System.Diagnostics.Process.Start(startInfo);
您还可以在Process.Start上看到MSDN site,有关于如何执行.exe并将参数传递给它的示例。
答案 1 :(得分:1)
ProcessStartInfo process = new ProcessStartInfo();
process.FileName = "yourprogram.exe";
process.Arguments = strCmdText; // or put your arguments here rather than the string
Process.Start(process);
答案 2 :(得分:0)
你试过吗
System.Diagnostics.Process.Start("CMD.exe "+strCmdText);
实际上在进一步检查时我认为你不需要调用CMD.EXE 您应该调用您的exe文件,除非您使用CMD来显示某些内容
string strCmdText = "..\\KatanaFirmware\\key-template.txt ..\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
System.Diagnostics.Process.Start("create-keyfile.exe", strCmdText);
答案 3 :(得分:0)
您是否尝试过使用/k or /c option
的cmd来自link
/ c:执行string指定的命令然后停止。
/ k:执行string指定的命令并继续。
string strCmdText = "/k create-keyfile.exe ..\\KatanaFirmware\\key-template.txt ..\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
答案 4 :(得分:0)
试试这个。
string strCmdText = "KatanaFirmware\\key-template.txt "+ "\\Keyfiles\\new-keyfile.txt " + cableTextBox.Text.Trim()+" " + startIdTextBox.Text.Trim();
Process mp = new Process();
mp.StartInfo.FileName = "E:\\create-keyfile.exe"; //path of the exe that you want to run
mp.StartInfo.UseShellExecute = false;
mp.StartInfo.CreateNoWindow = true;
mp.StartInfo.RedirectStandardInput = true;
mp.StartInfo.RedirectStandardOutput = true;
mp.StartInfo.Arguments = strCmdText;
mp.Start();
mp.WaitForExit();
希望它有所帮助。