开发者

How to run an exe which is added in the project

First of all I did gave a look at this one. But I didn't got the solution.

The accepted anser says to use it like this:

Process p = new Process(); 
p.StartInfo.UseShellExecute = false; 
p.Start开发者_Go百科Info.RedirectStandardOutput = true; 
p.StartInfo.FileName = "myExec.exe"; 
p.Start(); 

But this is not working for me. THe exception's message says "The system cannot find the specified file".

Am I missing something? I added the exe directly to the project itself.


Did you check if the .exe was actually there? I.e. in the bin\Debug folder? (assuming debug build).

You can set the .exe to be copied to the output directory via its properties in Visual Studio.


It sounds like the .exe file that you've added to the Visual Studio project is not being copied to the output directory (usually bin\Debug) on build.

Select the .exe in the Solution Explorer, and check the Properties (F4). There will be a property called "Copy to Output Folder" which you can set to "Only if Newer" or "Always".

That should let your process start method work with a relative path to the .exe, since it will always be in the same folder after a build.


"The system cannot find the specified file" indicates either the file is missing in the given path or the file path is wrong. Double check it.


The runtime unable to find the exe. Make sure that the Exe is already there in your build/release folder. You can also write post script which will copy the required exe from any other path to debug/release folder. This shall resolve the error you are getting.


For better using this method you can pack myExec.exe to resources, and if unpack it while runnig the programm. Using this you will be able ever know the right full path to your exe file. Just check the existence of myExec.exe befor runnig the process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜