Shell to an external .exe program and test return code
#1
Hi,
I want to shell/run/chain to an .exe (not necessarily a QB64 program) and test the return code from this .exe program.
The .exe will return 0 for okay or 1 for fail
How do I read in the returned code from the .exe program ?

Mike
Reply
#2
In DOS this is known as the ERRORLEVEL variable,

In QB64, the END command can set this variable:

http://www.qb64.net/wiki/index.php/END

Erik.
dndbbs project:

Links to my MUD: (strictly 16-bit); AKA XP:

Dndbbs executables
http://www.filegate.net/pdn/pdnbasic/dnd50a1e.zip

Dndbbs source
http://www.filegate.net/pdn/pdnbasic/dnd50a1s.zip

Dndbbs upgrade
http://www.filegate.net/pdn/pdnbasic/dnd50a1u.zip

DNDDOOR - https://bit.ly/EriksDNDDoor DUNGEON - https://bit.ly/EriksDungeon
Interpreter - https://bit.ly/EriksSICK Hex Editor - https://bit.ly/EriksHexEditor Utilities - https://bit.ly/EriksUtils
QB45 files: - https://bit.ly/EriksQB45 QB64shell - https://bit.ly/QB64shell Some old QB64 versions: - https://bit.ly/OldQB64
Reply
#3
Thank you ... but not quite the answer I want.

How do I read the errorlevel into the QB64 program that executed the .exe program

QB64ProgA ... executes ProgB.exe 
ProgB.exe sets the errorlevel on completion
QB64ProgA wants to read the errorlevel set by ProgB.exe to determine next action

QB64ProgA is an executable (.exe) program as well.
Reply
#4
(02-13-2018, 03:26 PM)eoredson Wrote: In DOS this is known as the ERRORLEVEL variable,

In QB64, the END command can set this variable:

http://www.qb64.net/wiki/index.php/END

Erik.

Oh wow, that's cool! 
Good question:  How does the caller program read that (the errorlevel)?
From Shell? Wiki END didn't say but linked to _HIDESHELL which..... dang!

I am trying to read Wiki but it is hanging up again... 3 days in a row!
B += x
Reply
#5
Oh hey! I got this thing to work!!!

(not with _SHELLHIDE but with SHELL)

Here is the sample Question program that asks if you like math jokes, notice how it ENDs:
Code:
'End test.bas 2018-02-13 point brought up by Erik
INPUT "If you like math jokes press anything and then enter, else just hit enter "; likesMathJokes$

IF LEN(likesMathJokes$) THEN
   PRINT "You have answered positively."
   END 42
ELSE
   PRINT "You have answered negatively."
   END -42
END IF

The .exe made of this is called "End test.exe"

Now the program to call "End test.exe" (3 times) and totals the answers of replies but there is hidden joke here:
Code:
'part 2 end test about liking math jokes.bas 2018-02-13

PRINT " OK I am going to ask you four times if you like math jokes."
_DELAY 3
FOR i = 1 TO 3
   'so see if our user likes math jokes by running an exe to find out
   likes% = SHELL("End test")
   'debug
   'PRINT "Shell returned this "; likes%
   IF likes% = 42 THEN total = total + 1
NEXT
PRINT: PRINT " OK,"; total; "out of four times, you like math jokes.  ; - )) "


Attached Files Thumbnail(s)

B += x
Reply
#6
Good catch! I did not know SHELL returned ERRORLEVEL variable!

Erik.
dndbbs project:

Links to my MUD: (strictly 16-bit); AKA XP:

Dndbbs executables
http://www.filegate.net/pdn/pdnbasic/dnd50a1e.zip

Dndbbs source
http://www.filegate.net/pdn/pdnbasic/dnd50a1s.zip

Dndbbs upgrade
http://www.filegate.net/pdn/pdnbasic/dnd50a1u.zip

DNDDOOR - https://bit.ly/EriksDNDDoor DUNGEON - https://bit.ly/EriksDungeon
Interpreter - https://bit.ly/EriksSICK Hex Editor - https://bit.ly/EriksHexEditor Utilities - https://bit.ly/EriksUtils
QB45 files: - https://bit.ly/EriksQB45 QB64shell - https://bit.ly/QB64shell Some old QB64 versions: - https://bit.ly/OldQB64
Reply
#7
Thank you for bring this to our attention.

It might be just the thing MLambert could use, if returning an integer will do.
B += x
Reply
#8
Thank you BPlus ... looks like exactly what I want ...

The program I am shell..ing to is not a QB64 but a C++ .exe .

I will give it a try and let you know what happens.

Mike
Reply
#9
As far as I know, C returns a error value after exit:

Code:
// crt_exit.c
// This program returns an exit code of 1. The
// error code could be tested in a batch file.

#include <stdlib.h>

int main( void )
{
exit( 1 );
}
dndbbs project:

Links to my MUD: (strictly 16-bit); AKA XP:

Dndbbs executables
http://www.filegate.net/pdn/pdnbasic/dnd50a1e.zip

Dndbbs source
http://www.filegate.net/pdn/pdnbasic/dnd50a1s.zip

Dndbbs upgrade
http://www.filegate.net/pdn/pdnbasic/dnd50a1u.zip

DNDDOOR - https://bit.ly/EriksDNDDoor DUNGEON - https://bit.ly/EriksDungeon
Interpreter - https://bit.ly/EriksSICK Hex Editor - https://bit.ly/EriksHexEditor Utilities - https://bit.ly/EriksUtils
QB45 files: - https://bit.ly/EriksQB45 QB64shell - https://bit.ly/QB64shell Some old QB64 versions: - https://bit.ly/OldQB64
Reply