我使用以下代码创建进程:
然后我启动这个过程并传递一些指令给它:
在这种情况下,进程会立即停止。StandardOut 显示如下内容:
由于原始脚本是使用 VS2010 提供的,因此无法更改该脚本。
编辑:我已更新问题并提供了更多细节。
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.WorkingDirectory = buildProject.DirectoryName;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
然后我启动这个过程并传递一些指令给它:
process.Start();
StreamWriter stream = process.StandardInput;
// call batch
stream.WriteLine(@"call ""test.bat""");
// call exe
stream.WriteLine("echo msbuild!");
// exit-command
stream.WriteLine("exit");
所有的工作正常,直到批处理文件包含两个NUL重定向:
@call :Jump_1
@call :Jump_2
@goto end
@REM -----------------------------------------------------------------------
:Jump_1
@echo Jump_1
@call :Jump_1_1 1>nul 2>&1 REM critical!!!
@exit /B 0
:Jump_1_1
@echo Jump_1_1
@exit /B 0
@REM -----------------------------------------------------------------------
:Jump_2
@echo Jump_2
@call :Jump_2_1 1>nul 2>&1 REM critical!!!
@exit /B 0
:Jump_2_1
@echo Jump_2_1
@exit /B 0
@REM -----------------------------------------------------------------------
@echo End
:end
在这种情况下,进程会立即停止。StandardOut 显示如下内容:
如果只有一个重定向,那么一切都正常,只有两个重定向时才会崩溃。Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Entwicklung\ProcessTest\ProcessTest\bin\Debug>call "test.bat"
Jump_1
Jump_2
由于原始脚本是使用 VS2010 提供的,因此无法更改该脚本。
编辑:我已更新问题并提供了更多细节。
2>&1
)失败了?你的代码没有将 RedirectStandardError 设置为 true... - Bob Vale