[英]Process.Start, WorkingDirectory, start one exe from another
I hope you will get my problem, dont know if I can describe it properly in english, but I will try :) 希望您能解决我的问题,不知道我是否可以用英语正确描述,但我会尝试:)
Situation: 情况:
Problem: 问题:
So, I am still learning C#, but could there be a problem with the workingdirectory? 因此,我仍在学习C#,但是workdirectory可能有问题吗? I am so confused, because the MainProg.exe has nothing to do with my xml file, it doesnt even know its there, the only point, where I use it is when loading values into SecondProg.exe...
我很困惑,因为MainProg.exe与我的xml文件无关,它甚至不知道它在那儿,唯一的一点,我使用它的地方是在将值加载到SecondProg.exe中时...
Inside my .cs file, I start the SecondProg via 在我的.cs文件中,我通过以下方式启动SecondProg
public override void Button()
{
Process.Start("Sub1\\Sub2\\SecondProg.exe");
}
So its like, MainProg has the button, in my .cs file I tell him what to onClick. 就像MainProg一样,在我的.cs文件中有按钮,我告诉他onClick。 well.. its hard to describe if you're not using your native language, but I hope you get what I mean ;)
好..很难描述您是否不使用母语,但我希望您明白我的意思;)
That SecondProg.exe apparently looks in its working directory for that file and fails if it doesn't find it. 该SecondProg.exe显然在其工作目录中查找该文件,如果找不到该文件,则失败。 As such, you have to set the working directory of the new process.
这样,您必须设置新进程的工作目录。 To do that, create a
ProcessStartInfo
object, set the FileName
to the path of the EXE file and the WorkingDirectory
to the path of the folder containing that EXE. 为此,创建一个
ProcessStartInfo
对象,将FileName
设置为EXE文件的路径,并将WorkingDirectory
设置为包含该EXE的文件夹的路径。 You then pass that object as an argument when you call Process.Start
. 然后,在调用
Process.Start
时,将该对象作为参数传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.