Reading standardoutput to a file
-
I am trying to call a program that comverts BMP to PPM formats. The exe to do so dumps the binary contents of the conversion to the console unless redirected as such
bmptoppm.exe input.bmp >output.ppm
I am attempting to call this exe from inside a different windows forms application and save the ouput to output.ppm. I am doing so using the process classProcess myProcess = new Process(); myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.Arguments = "C:\\input.bmp"; myProcess.StartInfo.FileName = "C:\\bmptoppm.exe"; myProcess.StartInfo.CreateNoWindow = false; myProcess.StartInfo.RedirectStandardOutput = true; myProcess.StartInfo.RedirectStandardError = true; myProcess.Start(); //file writing code here?
I am getting hung on on how exactly I can do the writing of the standardoutput to a file. Could someone point me in the right direction please? -
I am trying to call a program that comverts BMP to PPM formats. The exe to do so dumps the binary contents of the conversion to the console unless redirected as such
bmptoppm.exe input.bmp >output.ppm
I am attempting to call this exe from inside a different windows forms application and save the ouput to output.ppm. I am doing so using the process classProcess myProcess = new Process(); myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.Arguments = "C:\\input.bmp"; myProcess.StartInfo.FileName = "C:\\bmptoppm.exe"; myProcess.StartInfo.CreateNoWindow = false; myProcess.StartInfo.RedirectStandardOutput = true; myProcess.StartInfo.RedirectStandardError = true; myProcess.Start(); //file writing code here?
I am getting hung on on how exactly I can do the writing of the standardoutput to a file. Could someone point me in the right direction please?do something like:
SreamReader r=null;
StreamWriter w=null;//do your stuff => initialize the process+ Info
//now set the SreamReader and writer
w = myProcess.StandartInput
r= myProcess.StandardOutputfrom here it's just a matter of reding the output/r and saving to a specific name/path.
-
do something like:
SreamReader r=null;
StreamWriter w=null;//do your stuff => initialize the process+ Info
//now set the SreamReader and writer
w = myProcess.StandartInput
r= myProcess.StandardOutputfrom here it's just a matter of reding the output/r and saving to a specific name/path.
-
I should have been more specific. The part of saving to a specific file name/path is where I am lacking.
try this: use
string str = r.ReadToEnd();
to read the whole content of the StreamReader. Now get the bytes with something like this
byte[] rawbyte= Encoding.Default.GetBytes(str);
now write the bytes to a filestream or use custom bitmap encoding.
FileStream fs = new FileStream("yourfile.here", FileMode.OpenOrCreate);
fs.Write(data, 0, data.Length);hope it helps. I'm not sure if it will work. Read the conversation between me and Luc bellow for details of how ths idea came to me.
-
try this: use
string str = r.ReadToEnd();
to read the whole content of the StreamReader. Now get the bytes with something like this
byte[] rawbyte= Encoding.Default.GetBytes(str);
now write the bytes to a filestream or use custom bitmap encoding.
FileStream fs = new FileStream("yourfile.here", FileMode.OpenOrCreate);
fs.Write(data, 0, data.Length);hope it helps. I'm not sure if it will work. Read the conversation between me and Luc bellow for details of how ths idea came to me.
do you expect binary data to survive like that? I don't know, I never did that on Windows, and everything about stdin/out/err streams seems very text oriented... :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
do you expect binary data to survive like that? I don't know, I never did that on Windows, and everything about stdin/out/err streams seems very text oriented... :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
I don't know exactly. Maybe it works maybe not. Hence the "I hope it helps". :) Actually I did something like it. We have a tracing system in our ptoduction cells and all kind of mobile scanners. One particular kind of those scanners used to change the project comes with off course installers. Between the drivers there's a small utility that gets the "traffic" to and from the scanner on the particular COM port that was asigend to. Documentation 0 nada/rien/kaput/nothing. The program gets the human represntation of the "traffic" meaning text. Something like: "Sending ... to COMx. ... recieved". I had an idea in order to make it easier to use/maintain. But that idea ment sending the bytes to the scanner. The technigue I mentioned => Encoding.Default.GetBytes(...) where ... is the text command worked like a charm. :) Hence my maybe wrong hope of working to a larger set of data/string. PS: I'm not a prog. An IT guy. I should put that in my signature. It's empty anyways. :)
-
I don't know exactly. Maybe it works maybe not. Hence the "I hope it helps". :) Actually I did something like it. We have a tracing system in our ptoduction cells and all kind of mobile scanners. One particular kind of those scanners used to change the project comes with off course installers. Between the drivers there's a small utility that gets the "traffic" to and from the scanner on the particular COM port that was asigend to. Documentation 0 nada/rien/kaput/nothing. The program gets the human represntation of the "traffic" meaning text. Something like: "Sending ... to COMx. ... recieved". I had an idea in order to make it easier to use/maintain. But that idea ment sending the bytes to the scanner. The technigue I mentioned => Encoding.Default.GetBytes(...) where ... is the text command worked like a charm. :) Hence my maybe wrong hope of working to a larger set of data/string. PS: I'm not a prog. An IT guy. I should put that in my signature. It's empty anyways. :)
OK thanks. I hope the OP will tell us the outcome. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
OK thanks. I hope the OP will tell us the outcome. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
sun?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
sun?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
sun?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
never mind I got it. It should be son not sun.
Just an irritated, ranting sun of an IT guy