Results 1 to 4 of 4

Thread: exit /b 23 in a .bat file returns 0 from QProcess::exitCode

  1. #1
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android Maemo/MeeGo

    Default exit /b 23 in a .bat file returns 0 from QProcess::exitCode

    I have a batch file (ppp.bat) with only two lines in it:
    Qt Code:
    1. start .
    2. exit /b 23
    To copy to clipboard, switch view to plain text mode 

    The C++ code to call QProcess::start is this:

    Qt Code:
    1. QString program = "c:\\ppp.bat";
    2.  
    3. QProcess *myProcess = new QProcess(this);
    4.  
    5. myProcess->start(program);
    6. myProcess->waitForStarted();
    7.  
    8. myProcess->waitForFinished(1000);
    9.  
    10. QString strExitCode( "ExitCode is %1 ExitStatus is %2");
    11.  
    12. strExitCode = strExitCode.arg( myProcess->exitCode()).arg( (int) myProcess->exitStatus());
    13.  
    14. ui->textEdit->append( strExitCode);
    To copy to clipboard, switch view to plain text mode 


    It always prints 0 for exitCode.

    What is needed to have this function return 23?

    Oh the OS is Windows XP SP 3 and the Qt is 4.8.1 compiled with VS2010.

    Thanks.
    Last edited by Agroni; 14th September 2012 at 15:24.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: exit /b 23 in a .bat file returns 0 from QProcess::exitCode

    Perhaps you need to execute your bat file through a call to "cmd": "cmd c:\\ppp.bat" I believe that this is what is actually happening when Windows executes a bat file, and in your case the error code is probably being returned to the temporary MS-DOS cmd process that then eats it and returns the normal 0 exit code when it exits.

  3. #3
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android Maemo/MeeGo

    Default Re: exit /b 23 in a .bat file returns 0 from QProcess::exitCode

    That didn't work.

    What I tried later was

    Qt Code:
    1. QString program = "cmd /C \"call c:\\ppp.bat\" ";
    To copy to clipboard, switch view to plain text mode 

    Which has no consistent results. Even if this code is ran repeatedly w/o any change. It sometimes returns the right exit code. But sometimes not.

    I trusted this documentation here:
    http://www.microsoft.com/resources/d...n-us/exit.mspx

    The second remark says that exit /b will set the ERRORLEVEL to the given exitcode. And will also set the exitcode of the process when cmd.exe quits.

    All I am seeing is random behavior.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: exit /b 23 in a .bat file returns 0 from QProcess::exitCode

    When you get to running the actual command you want to execute, will this be a bat file also? Or will it be an EXE instead? If it is to be an EXE, then just mock up a dummy one that returns 23 on exit and see if you get something consistent there. It could just be something weird in the bat file execution interface that is causing this.

Similar Threads

  1. Replies: 1
    Last Post: 19th August 2012, 17:08
  2. Ping and QProcess (exitcode() question)
    By hakermania in forum Qt Programming
    Replies: 3
    Last Post: 30th August 2011, 23:29
  3. QProcess.pid() returns wrong pid in PyQt(windows)
    By vertusd in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2011, 07:57
  4. Question about QProcess::ExitCode() !
    By jackmack in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2010, 09:38
  5. exitCode problem in QProcess
    By mattia in forum Newbie
    Replies: 7
    Last Post: 26th November 2007, 15:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.