Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reading standardoutput to a file

Reading standardoutput to a file

Scheduled Pinned Locked Moved C#
winformsquestion
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    svanwass
    wrote on last edited by
    #1

    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 class Process 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?

    D 1 Reply Last reply
    0
    • S svanwass

      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 class Process 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?

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

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

      from here it's just a matter of reding the output/r and saving to a specific name/path.

      S 1 Reply Last reply
      0
      • D Dan Mos

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

        from here it's just a matter of reding the output/r and saving to a specific name/path.

        S Offline
        S Offline
        svanwass
        wrote on last edited by
        #3

        I should have been more specific. The part of saving to a specific file name/path is where I am lacking.

        D 1 Reply Last reply
        0
        • S svanwass

          I should have been more specific. The part of saving to a specific file name/path is where I am lacking.

          D Offline
          D Offline
          Dan Mos
          wrote on last edited by
          #4

          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.

          L 1 Reply Last reply
          0
          • D Dan Mos

            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.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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.


            D 1 Reply Last reply
            0
            • L Luc Pattyn

              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.


              D Offline
              D Offline
              Dan Mos
              wrote on last edited by
              #6

              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. :)

              L 1 Reply Last reply
              0
              • D Dan Mos

                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. :)

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                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.


                D 1 Reply Last reply
                0
                • L Luc Pattyn

                  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.


                  D Offline
                  D Offline
                  Dan Mos
                  wrote on last edited by
                  #8

                  Me too.

                  Just an irritated, ranting sun of an IT guy

                  L 1 Reply Last reply
                  0
                  • D Dan Mos

                    Me too.

                    Just an irritated, ranting sun of an IT guy

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    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.


                    D 2 Replies Last reply
                    0
                    • L Luc Pattyn

                      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.


                      D Offline
                      D Offline
                      Dan Mos
                      wrote on last edited by
                      #10

                      did i spelled something wrong?

                      Just an irritated, ranting sun of an IT guy

                      1 Reply Last reply
                      0
                      • L Luc Pattyn

                        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.


                        D Offline
                        D Offline
                        Dan Mos
                        wrote on last edited by
                        #11

                        never mind I got it. It should be son not sun.

                        Just an irritated, ranting sun of an IT guy

                        S 1 Reply Last reply
                        0
                        • D Dan Mos

                          never mind I got it. It should be son not sun.

                          Just an irritated, ranting sun of an IT guy

                          S Offline
                          S Offline
                          svanwass
                          wrote on last edited by
                          #12

                          Wow. Responses to the dome. I will attempt it and get back.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups