Process Question

S

Scott B

I have a EXE that spits out text in XML fomat.
I need to call this exe and have it write the XML to a file

I am using the following code:
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.FileName = "GetData.exe";
p.StartInfo.Arguments = @" -listxml > c:\Output.xml";

p.Start();


My problem is that it never writes the output.xml
If I could rewrite the original application to spit out the data to a file I
would, but I am stuck using it as it stands.

Any ideas>
 
G

Greg Young

I would think that you would want RedirectStadardOutput to true .. (then
just read the datastream and write it to a file.

The reason it is not working is that > is handled by the command prompt ..
(it redirects standard output to a file). If you wanted to use it you would
have to actually shell out to cmd and passing the program etc as the
arguments.
http://www.c-sharpcorner.com/References/System.Diagnostic.Process.asp
includes an example of reading the output of the program, it is just a
matter of writing the data to a filestream from there.

Cheers,

Greg Young
MVP - C#

Also
 
C

Chris Dunaway

In your arguments list, the "> C:\Output.xml" part is not recognized by
the GetData.exe. Those arguments are recognized only cmd.exe, the
command line, which is what you would normally run this program in.
That's why you did not get any output file created.

I agree with Greg Young, set RedirectStandardOutput to true and read
the data from the stream and output it to a file.
 
C

Chris Dunaway

I just noticed that you also explained about the command prompt so
please ignore my post!!
 
S

Scott B

Brilliant. I suppose I should have spent some more time delving into the
process class...



"Scott B"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top