Process.Start() 第一次后不执行我的命令
Process.Start() not Executing my Command after the First Time
我有以下启动 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 "。
感谢您的宝贵时间。
makensis.exe是一个控制台程序,使用cmd.exe作为中间人调用makensis.exe是一无所获的。恰恰相反,通过将 cmd.exe 加入组合,您将接触到它的 &
/&&
/||
运算符和奇怪的引用处理。
我建议您直接开始 makensis.exe。
如果您出于某种原因认为必须使用 cmd.exe,那么命令行应该类似于 cmd.exe /C if 1==1 "c:\path\otherapp.exe" "c:\inputfile.ext"
/C
指示cmd.exe执行命令然后退出
if 1==1
是一种减少奇怪引用处理的 hack
我有以下启动 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 "。
感谢您的宝贵时间。
makensis.exe是一个控制台程序,使用cmd.exe作为中间人调用makensis.exe是一无所获的。恰恰相反,通过将 cmd.exe 加入组合,您将接触到它的 &
/&&
/||
运算符和奇怪的引用处理。
我建议您直接开始 makensis.exe。
如果您出于某种原因认为必须使用 cmd.exe,那么命令行应该类似于 cmd.exe /C if 1==1 "c:\path\otherapp.exe" "c:\inputfile.ext"
/C
指示cmd.exe执行命令然后退出if 1==1
是一种减少奇怪引用处理的 hack