C#启动一个EXE,直到完全启动,然后附加参数
我试图通过process.start开始使用参数。 我的第一个尝试是使用process.start(“/of/of/of/of/the/exe”,“ exe的参数”)。 这是我的代码片段:
Process.Start(@"D:\Program Files\ITASCA\UDEC700\Exe64\udecConsole2017.exe", @"call 'D:\Work\202205\20220525\tunnel-for-cmd.txt'");
但是,此EXE的初始化有点慢,结果是,我只能启动EXE,而是通过参数失败。以下是屏幕截图: 这与没有参数开始的结果完全相同。
通过引用此帖子 c# - 制作过程。开始等待该过程具有启动,我将代码更改为以下:
var process = Process.Start(@"D:\Program Files\ITASCA\UDEC700\Exe64\udecConsole2017.exe", @"call 'D:\Work\202205\20220525\tunnel-for-cmd.txt'");
while (string.IsNullOrEmpty(process.MainWindowTitle))
{
System.Threading.Thread.Sleep(100);
process.Refresh();
}
但是这些更改不起作用。
我认为我的目标是等到EXE完全启动,然后用参数运行它,但我不知道该如何实施。
=============================================== ===
新加法: 如果我输入参数调用'd:\ work \ 202205 \ 20220525 \ tunnel-for-cmd.txt'在此开始过程中,我将得到我的结果: 所以我认为输入论点应该可以吗?
====================================== 新添加2:
I was trying to start a exe with arguments by Process.Start.
My first try is using Process.Start("Path/of/the/exe", "arguments of exe").
Here's my code snippets:
Process.Start(@"D:\Program Files\ITASCA\UDEC700\Exe64\udecConsole2017.exe", @"call 'D:\Work\202205\20220525\tunnel-for-cmd.txt'");
However the initialization of this exe is a bit slow, and the result is, I can only start the exe but the failed passing arguments. The following is the screenshot:
which is exactly the same result that starts without arguments.
By referencing this post C# - Making a Process.Start wait until the process has start-up, I changed my code as follows:
var process = Process.Start(@"D:\Program Files\ITASCA\UDEC700\Exe64\udecConsole2017.exe", @"call 'D:\Work\202205\20220525\tunnel-for-cmd.txt'");
while (string.IsNullOrEmpty(process.MainWindowTitle))
{
System.Threading.Thread.Sleep(100);
process.Refresh();
}
however these changes does not work.
I think my goal is to wait until exe completely started and then run it with arguments, but I dont know how to implement this.
=====================================================
New additions:
if I type in arguments call 'D:\Work\202205\20220525\tunnel-for-cmd.txt' in this started process, I will get my result:
SO I think the input arguments should be OK?
=======================================
new addition 2:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来这是一个控制台应用程序,您将在控制台启动后输入。该键入不是参数:仅在启动新过程而永不更改时提供参数。
您正在做的是为程序的标准输入提供一些东西。控制台程序具有OS提供的三个流(一个输入和两个输出)。您需要重定向它们以检测程序何时启动并提供适当的输入。
这样的事情:
It appears this is a console application and you are typing in the console after it starts. This typing is not arguments: Arguments are provided only when starting a new process and never change.
What you are doing is providing something to the standard input of the program. Console programs have three streams the OS provides (one input and two output). You need to redirect these to detect when the program has started and to provide the proper input.
Something like this: