【发布时间】:2015-10-30 16:13:25
【问题描述】:
我有以下代码启动 cmd.exe 然后执行 NSIS 脚本的编译。
...
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo()
{
FileName = "cmd.exe",
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
};
process.StartInfo = startInfo;
if (!process.Start())
throw new Exception("NSIS failed to start, find out why");
process.StandardInput.WriteLine(String.Format("\"{0}\" {1}", nsisExePath, packagePath));
process.StandardInput.WriteLine("exit");
//process.WaitForExit();
这在我第一次执行代码时完美运行。但是,在同一会话中运行此进程的所有后续尝试都会失败。我必须重新启动我的应用程序才能让它再次工作。我已经注释掉了 WaitForExit() 方法,因为这似乎会导致进程挂起 - cmd.exe 进程似乎永远不会到达 exit 命令。
我怎样才能让 NSIS 进程正确退出,或者我怎样才能让它在一个会话中多次工作,我错过了什么?
我用来编译 NSIS 脚本的显式命令是“C:\Program Files (x86)\NSIS\makensis.exe”。
感谢您的宝贵时间。
【问题讨论】:
-
您重定向了 StandardOutput 但您从未真正读取过它,也许这就是问题所在?还有,你为什么要启动 cmd.exe 而不是直接启动
nsisExePath?