CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    7

    Process in/out-Put to Streams in DOS-Box-like utility

    Hi!

    I´m currently programming a GUI for a Command-Line-Based System. The administration is done with a command-line-Admin-Tool similar to Windows´ CMD-Dos-Box.

    Unfortunately i cannot run the admin-commands on their own, because the only run in this cmd-line-based gui, which seems to be an stand-alone interpreter, not a dos-box running seperate programs...

    Also there is no API available i could use.

    What i´d like to do is to call a DOS-Box/Admin-Tool via the Process-Object and send my commands to it via the StandardInput-Object.

    Sending works fine, but when I do the reading from StandardOutput-Stream, i cannot find an end-mark for my while-Statement.
    (For testing-purposes i send everything to the system-console in order to see, what comes back from my process)

    string sto = null;
    string ste = null;
    while ( ((sto = process.StandardOutput.ReadLine()) != null) || ((ste = process.StandardError.ReadLine()) != null) )
    {
    if (sto != null)
    System.Console.WriteLine(sto);
    if (ste != null)
    System.Console.WriteLine(ste);
    sto = null;
    ste = null;
    }

    When the command has finished, the loop hangs in the ReadLine-Statements.

    Peeking into the stream doesn´t work and hangs also...

    How could i do this?

    Thanks a lot!

    J.

  2. #2
    Join Date
    Dec 2005
    Posts
    31

    Re: Process in/out-Put to Streams in DOS-Box-like utility

    is this what you're looking for ?

    StreamReader output = Process.StandardError;
    string stdout = output.ReadToEnd();

    maybe you don't need the while loop ?

  3. #3
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Process in/out-Put to Streams in DOS-Box-like utility

    you need to read the output (and error) stream in a seperate thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured