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. redirecting output from an unmanaged console application

redirecting output from an unmanaged console application

Scheduled Pinned Locked Moved C#
helpquestion
3 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.
  • E Offline
    E Offline
    erikash
    wrote on last edited by
    #1

    Hi guys, i'm executing a console application using : Process prsAlgorithm = new Process(); prsAlgorithm.StartInfo.WindowStyle = ProcessWindowStyle.Normal; prsAlgorithm.StartInfo.FileName = "Lottery.exe"; prsAlgorithm.StartInfo.UseShellExecute = false; prsAlgorithm.StartInfo.RedirectStandardInput = true; prsAlgorithm.StartInfo.RedirectStandardOutput = true; prsAlgorithm.Start(); System.IO.StreamWriter swWriter = prsAlgorithm.StandardInput; System.IO.StreamReader srReader = prsAlgorithm.StandardOutput; swWriter.WriteLine(m_strArgList); swWriter.Close(); // Some thing goes here prsAlgorithm.WaitForExit(); i need to redirect the output of this console application to a textbox on a window form, but the problem is that i want that every line written in the console application, would be automaticaly written to the textbox (and not wait until the console application has exited)... i'm pretty sure it has something to do with asynchronousy reading a stream or something like that...? any suggestions? Thanks in advance, Erik.

    U S 2 Replies Last reply
    0
    • E erikash

      Hi guys, i'm executing a console application using : Process prsAlgorithm = new Process(); prsAlgorithm.StartInfo.WindowStyle = ProcessWindowStyle.Normal; prsAlgorithm.StartInfo.FileName = "Lottery.exe"; prsAlgorithm.StartInfo.UseShellExecute = false; prsAlgorithm.StartInfo.RedirectStandardInput = true; prsAlgorithm.StartInfo.RedirectStandardOutput = true; prsAlgorithm.Start(); System.IO.StreamWriter swWriter = prsAlgorithm.StandardInput; System.IO.StreamReader srReader = prsAlgorithm.StandardOutput; swWriter.WriteLine(m_strArgList); swWriter.Close(); // Some thing goes here prsAlgorithm.WaitForExit(); i need to redirect the output of this console application to a textbox on a window form, but the problem is that i want that every line written in the console application, would be automaticaly written to the textbox (and not wait until the console application has exited)... i'm pretty sure it has something to do with asynchronousy reading a stream or something like that...? any suggestions? Thanks in advance, Erik.

      U Offline
      U Offline
      umseker
      wrote on last edited by
      #2

      .... System.Diagnostics.Process pr = new System.Diagnostics.Process(); pr.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; pr.StartInfo.FileName = "cmd.exe"; pr.StartInfo.UseShellExecute = false; pr.StartInfo.RedirectStandardInput = true; pr.StartInfo.RedirectStandardOutput = true; pr.Start(); pr.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(pr_OutputDataReceived); pr.BeginOutputReadLine(); System.IO.StreamWriter swWriter = pr.StandardInput; swWriter.WriteLine("echo SomeTextHere\n"); swWriter.Flush(); .... void pr_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e) { MessageBox.Show(e.Data); }

      UMS

      1 Reply Last reply
      0
      • E erikash

        Hi guys, i'm executing a console application using : Process prsAlgorithm = new Process(); prsAlgorithm.StartInfo.WindowStyle = ProcessWindowStyle.Normal; prsAlgorithm.StartInfo.FileName = "Lottery.exe"; prsAlgorithm.StartInfo.UseShellExecute = false; prsAlgorithm.StartInfo.RedirectStandardInput = true; prsAlgorithm.StartInfo.RedirectStandardOutput = true; prsAlgorithm.Start(); System.IO.StreamWriter swWriter = prsAlgorithm.StandardInput; System.IO.StreamReader srReader = prsAlgorithm.StandardOutput; swWriter.WriteLine(m_strArgList); swWriter.Close(); // Some thing goes here prsAlgorithm.WaitForExit(); i need to redirect the output of this console application to a textbox on a window form, but the problem is that i want that every line written in the console application, would be automaticaly written to the textbox (and not wait until the console application has exited)... i'm pretty sure it has something to do with asynchronousy reading a stream or something like that...? any suggestions? Thanks in advance, Erik.

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        Have a look at this[^] article, it does exactly that.

        Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

        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