在 C# 中将参数传递给正在运行的进程
我在运行进程并将参数传递给它们时遇到一些麻烦。 我知道如何使用一些参数运行进程
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/c something");
Process p = Process.Start(psi)
问题是执行脚本后进程被终止。这就是为什么有“/c”,
但我正在运行多个脚本,我想在一个进程(“cmd.exe”)中运行它们,而不是每次都启动新进程。
有一些解决方案吗?
我希望有人能理解我在说什么;)
I've some troubles with running processes and passing args to them.
I know how to run process with some args
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/c something");
Process p = Process.Start(psi)
The problem is that after script is executed process is terminated. That's why there is "/c"
But I'm running multiple scripts and I would like to run them in one process ("cmd.exe") not to start new process every time.
Is there some solutions for it ?
I hope somebody understand what I'm talking about ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您使用批处理文件来编写可执行文件的执行脚本并调用批处理文件。或者,你可以这样做 -
I recommend you utilize a batch file to script the execution of your executables and call your batch file instead. Or, you can do this -
听起来您应该研究重定向标准输入 - 请务必将 psi.UseShellExecute 设置为 false。您可能还想重定向标准输出,这样您就可以通过某种方式了解您的子进程正在做什么。
此处。
It sounds like you ought to investigate redirecting the standard input - be sure to also set
psi.UseShellExecute
tofalse
. You'll probably also want to redirect standard output, so you can have some way of knowing what your child process is doing.Read more about redirection here.