Reply to Thread

Post a reply to the thread: Read console output from

Your Message

Click here to log in

What's the name of our main installation product (in uppercase letters), directly followed by the current year?

 

You may choose an icon for your message from this list

Additional Options

  • Will turn www.example.com into [URL]http://www.example.com[/URL].

Topic Review (Newest First)

  • 08-11-2014, 03:31 PM
    linder

    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
  • 08-11-2014, 02:32 PM
    linder

    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
  • 08-11-2014, 02:21 PM
    MarkDynna

    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.
  • 08-11-2014, 12:13 PM
    linder

    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
  • 08-11-2014, 12:00 PM
    MarkDynna

    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?
  • 08-11-2014, 11:50 AM
    linder

    Re: Read console output from

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

    Friedrich
  • 08-11-2014, 11:29 AM
    MarkDynna

    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.
  • 08-11-2014, 10:51 AM
    linder

    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
  • 08-11-2014, 10:41 AM
    MarkDynna

    Re: Read console output from

    So, is there a way to run an external program, get the return code and the console output?
  • 08-09-2014, 02:59 AM
    linder

    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
This thread has more than 10 replies. Click here to review the whole thread.

Posting Permissions

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