tags:

views:

108

answers:

5

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.StartInfo.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.

A: 

"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.

Sri Kumar
The file is in my project. Checked in windows explorer too. It's there.
Manish
Try giving the complete path
Sri Kumar
+6  A: 

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.

mookid8000
Hmmm....that was missing part...thanks....
Manish
+2  A: 

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.

Coxy
Yes, that was missing...but mookid did answered that... :)
Manish
A: 

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.

Ram
A: 

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.

Stremlenye