Cannot start .exe application using C # code

I have an exe that I need to call from my C # Program with two arguments (PracticeId, ClaimId)

For example: Suppose I have a test.exe application whose functionality is to make a request in accordance with these two arguments.

In cmd, I usually issued the following command:

test.exe 1 2

And it works great and does its conversion work.

But I want to accomplish the exact same thing using my C # code. I am using the following code example:

 Process compiler = new Process(); compiler.StartInfo.FileName = "test.exe" ; compiler.StartInfo.Arguments = "1 2" ; compiler.StartInfo.UseShellExecute = true; compiler.StartInfo.RedirectStandardOutput = true; compiler.Start(); 

When I try to call test.exe using the above code, it cannot do its job of creating a txt file claim.

Where is the problem with this? Whether the problem is a thread or not, I don't know.

Can someone please tell me what I need to change in the above code?

+4
c #
Mar 31 '10 at 4:06
source share
4 answers

The code you provided does not work with the following error on startup:

System.InvalidOperationException

The Process object must have the UseShellExecute property set to false to redirect input / output streams.

The following code runs correctly and passes arguments through:

 var compiler = new Process(); compiler.StartInfo.FileName = "test.exe"; compiler.StartInfo.Arguments = "1 2"; compiler.StartInfo.UseShellExecute = true; compiler.StartInfo.RedirectStandardOutput = false; compiler.Start(); 
+3
Mar 31 '10 at 4:50
source share

although I have not tested my code yet, but hope this helps you do what you want to do ...

Process.Start ("xyz.exe", "1 2");

Let me know if this works or not.

+1
Mar 31 '10 at 4:37
source share

Check what is your working directory. Is test.exe in your path? If not, you will need to specify a path. Good practice is to provide a path if you know where it is. You can dynamically build this from the application path, the build path, or customization preferences.

0
Mar 31 '10 at 4:38
source share

MSDN should help. They look like they have updated the site, and the example for your specific question is very detailed.

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

0
Mar 31 '10 at 4:40
source share



All Articles