[英]C# Run console application from another app in a new console window
第二個應用程序是一個控制台應用程序,我想看到它的輸出窗口。
我知道如何使用Process.Start()
但它沒有顯示應用程序的控制台窗口。 這是我嘗試過的:
Process.Start("MyApp.exe", "arg1 arg2");
那么怎么做呢?
也許這有幫助:
ProcessStartInfo info = new ProcessStartInfo(fileName, arg);
info.CreateNoWindow = false;
info.UseShellExecute = true;
Process processChild = Process.Start(info);
我想到了。 我必須使用/k
參數運行cmd
命令(以保持控制台窗口打開),然后是我的整個命令行:
var command = "MyApp.exe arg1 arg2";
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd", "/k " + command);
processStartInfo.UseShellExecute = false;
Process process = new Process();
process.StartInfo = processStartInfo;
process.Start();
//In case you need the output. But you have to wait enough for the output
//string text = process.StandardOutput.ReadToEnd();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.