[英]Passing multiple arguments to running console application from windows form
我有控制台应用程序,将其命名为X.exe 。 它与两个参数一起工作,比如说'a'和'a.tmp',其中a 是我的输入文件名 , a.tmp 是输出filename 。 在控制台上,我通常运行如下应用程序: X a a.tmp, 但首先我必须在输入文件'a'的位置出现,否则,如果我尝试给出其绝对路径,则应用程序将无法工作。 我已经创建了Windows窗体来运行这些控制台应用程序,但是正如我之前所说,必须在文件位置启动该应用程序。 我尝试使用过程对象,但应用程序无法正常工作。 我创建了两个过程:
Question: can I excute these multiple commands in one go and avoid using IPC?
您可以使用ProcessStartInfo.WorkingDirectory
。
例如,来自MS Docs-ProcessStartInfo类
当
UseShellExecute
为true
时,WorkingDirectory
属性的行为与UseShellExecute
为false
时的行为不同。 当UseShellExecute
为true
,WorkingDirectory
属性指定可执行文件的位置。 如果WorkingDirectory
是一个空字符串,则当前目录将被理解为包含可执行文件。注-当
UseShellExecute
为true
,启动可执行文件的应用程序的工作目录也是可执行文件的工作目录。如果
UseShellExecute
为false
,则不使用WorkingDirectory
属性查找可执行文件。 相反,它的值适用于已启动的流程,并且仅在新流程的上下文中具有含义。
例如
public static void Main()
{
Process myProcess = new Process();
try
{
myProcess.StartInfo.UseShellExecute = true;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "X.exe"; /
myProcess.WorkingDirectory = "C:\SomeDirectory That contains A and A.tmp"
myProcess.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.