我正在将批处理脚本迁移到.Net核心,我试图从当前终端打开另一个终端并运行命令(我不需要stderr o stout)。.Net核心打开外部终端
批量只需要这个命令:start cmd /K gulp
。我试图用.Net核心做同样的事情,但只能找到在当前终端内运行命令的方式。
private static string Run(){
var result = "";
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = $"/c \"gulp browserSync\"";
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
using (Process process = Process.Start(startInfo))
{
result = process.StandardError.ReadToEnd();
process.WaitForExit();
}
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
Console.ReadKey();
}
return result;
}
我想,才能在另一端,打开更改此属性:
startInfo.RedirectStandardOutput = false;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = true;
但是破例:
UseShellExecute必须始终设置为false。
究竟是什么问题?你想打开一个新的终端,它不会正确吗? –
我在一个终端上,我试图打开一个新终端并运行一个命令。 – Equiman