CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    Chennai, India
    Posts
    3

    Capture DOS output in VC++

    Hi All

    I execute a .bat file from my application (In VC++ 6)
    & I would like to display the output in a control of my application.

    how can I capture DOS output in VC++.

    Thanks in advance
    rm_pkt

  2. #2
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    Set the
    Code:
      HANDLE hStdInput;
      HANDLE hStdOutput;
      HANDLE hStdError;
    members of the STARTUPINFO struct, and set the STARTF_USESTDHANDLES flag in the dwFlags member, for your call to CreateProcess.
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  3. #3
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    The following only provides an overview but also specifies where else to look.

    32-bit console programs and DOS programs normally have Standard I/O files that can be used for simple I/O (see Console Handles and stdin, stdout, stderr). A 32-bit Windows program can "redirect" Standard I/O (for a 32-bit console program or DOS program that it invokes by CreateProcess) by opening files and specifying the handles in the call to CreateProcess. Note that Windows GUI (non-console) programs do not have the Standard I/O files available to them unless they first create a console for themselves. See Q105305 - INFO: Calling CRT Output Routines from a GUI Application.

    The redirection capability can be used by a GUI program to provide input to a console or DOS program and then to capture the output for display in an edit control or something like that. The "Pipe Handle Inheritance" topic of the Platform SDK documentation describes the functions used and the topic Creating a Child Process with Redirected Input and Output has an example. Also see the following Knowledge Base articles:
    • Q190351 - HOWTO: Spawn Console Processes with Redirected Standard Handles
    • INFO: Redirection Issues on Windows 95 MS-DOS Applications

    There also are some CodeGuru articles about redirecting Standard I/O. The following articles describe redirecting standard I/O but this is an incomplete list of what is available.
    • Redirecting Standard Output to a CEdit Control
    • Redirect Output of CMD.EXE to a Pipe


    Using the Command Line
    If you want to use the redirection operators (">", "<" or "|") in a command line for a DOS program or DOS command, then you can use CreateProcess to execute the command processor and pass a command with the redirection operators as a parameter. Note that the command processor is Command.com for Windows 95 and Cmd.exe for NT.

    I am not sure if this works for a 32-bit console program too. Part of what I know says yes and part says no. I should try it sometime.

    Pipes
    A pipe is something that originated in the Unix operating system. Imagine a program that writes to a file and then another program that reads from that file. A pipe is something that the operating system creates that works like two files. When a program writes to the pipe the data is provided to another program as if it is input. So the data flows from program to program as if through a pipe.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  4. #4
    Join Date
    Nov 2003
    Location
    Chennai, India
    Posts
    3
    Thanks vicodin451, Sam Hobbs

    Your reply is very useful to me.

    Thanks a lot.
    rm_pkt

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