win*_*nry 5 c# cygwin windows-console
我正在尝试通过 C# 中的 bash 运行 cygwin 命令,并尝试使用 read 命令保持结果打开。我的代码似乎是打开 bash 然后立即关闭。我究竟做错了什么?
static void Main(string[] args)
{
Process bashProcess = new Process();
bashProcess.StartInfo.FileName = @"C:\cygwin64\bin\bash.exe";
bashProcess.StartInfo.Arguments = "-l -c echo blah; read";
bashProcess.StartInfo.UseShellExecute = true;
bashProcess.Start();
bashProcess.WaitForExit();
System.Console.WriteLine("Exit Code: {0}", bashProcess.ExitCode);
System.Console.WriteLine("Press enter to exit...");
System.Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
刚刚找到解决方案。用单引号将整个命令括起来使其起作用。所以
bashProcess.StartInfo.Arguments = "-l -c echo blah; read";
Run Code Online (Sandbox Code Playgroud)
应替换为以下内容:
bashProcess.StartInfo.Arguments = "-l -c 'echo blah; read'";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1861 次 |
| 最近记录: |