+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Read console output from

  1. #11
    Join Date
    Mar 2004
    Posts
    4,307

    Default Re: Read console output from

    I have developed and uploaded a "catch exit code" demo for you:

    http://www.lindersoft.com/forums/sho...8240#post78240

    Friedrich

  2. #12

    Default Re: Read console output from

    So, is there a way to run an external program, get the return code and the console output?

  3. #13
    Join Date
    Mar 2004
    Posts
    4,307

    Default Re: Read console output from

    This should do it:

    http://www.lindersoft.com/forums/sho...8220#post78220

    The standard ">" Windows command redirects output from a console app to a text file and then just catch the exit code (if the app returns any).

    The %_SB_ERRORCODE% return value can also hold the last exit code returned by the executable associated with the work item on its last run.

    The %_SB_RETURNEX% variable holds the error code provided by the GetLastError Windows API if the CreateProcess function failed. It holds a system error code if a call to the ShellExecuteEx API failed.

    Friedrich

  4. #14

    Default Re: Read console output from

    Right, but I seem to be caught in a no-win situation with the external installer I'm running.

    "Run Program" returns the error code back to SetupBuilder, but I can't get the console output: the ">" operator doesn't work.

    "Run Command Line" generates the console output, but doesn't return the error code to SetupBuilder.

  5. #15
    Join Date
    Mar 2004
    Posts
    4,307

    Default Re: Read console output from

    ">" definitely works because it is a Windows "switch" ;-)

    Friedrich

  6. #16

    Default Re: Read console output from

    Quote Originally Posted by linder View Post
    ">" definitely works because it is a Windows switch ;-)

    Friedrich
    Should it work as part of SetupBuilder's "Run Program" statement?

  7. #17
    Join Date
    Mar 2004
    Posts
    4,307

    Default Re: Read console output from

    It has nothing to do with SetupBuilder's "Run Program" statement. The statement is just a wrapper around CreateProcess or ShellExecuteEx. Windows handles all the ">" redirection behind the scenes.

    See attached screenshots. This "Run Program" function calls the good old PKUNZIP.EXE from 1993 and redirects the console output to the RESULT.TXT file.

    Friedrich
    Attached Images Attached Images   

  8. #18

    Default Re: Read console output from

    Ok, not sure what I'm doing wrong then. My Run Program command looks a lot like the one you have above. The command line parameters are really long, is there some sort of "hidden character limit" I'm running into. If I take the exact same line and run it manually in a command window, the console output is redirected properly. Running the same command through SetupBuilder doesn't redirect the console output.
    Attached Images Attached Images  

  9. #19
    Join Date
    Mar 2004
    Posts
    4,307

    Default Re: Read console output from

    Please note that there is a fundamental difference between running an application from an OS "Command Prompt" and via the CreateProcess or ShellExecuteEx API !!!

    BTW, the comment line limit is 1,024 bytes.

    Friedrich

  10. #20
    Join Date
    Mar 2004
    Posts
    4,307

    Default Re: Read console output from

    Mark,

    I have created a simple quick-and-dirty demo for you on how to catch the return code and redirect console messages into out.txt (from a "Run Program..." command):

    http://www.lindersoft.com/projects/markd.zip

    Unzip the archive and compile and RUN the "MarkD.sb8" project file. It will launch a dummy "console1.exe" and displays its exit code (should display "951"). The redirection writes "Hello, this is a test output from a Win32 console app." to a "out.txt" ASCII text file. This method "should" work fine with DOS, Win32/64 and MFC console apps. But no guarantee because it depends on a secret/undocumented Windows feature

    Friedrich
    Attached Images Attached Images   

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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