繁体   English   中英

第一次后,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可以减少奇怪的报价处理

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM