User Tools

Site Tools


reading_20the_20exit_20code_20of_20a_20dos_20utility

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

reading_20the_20exit_20code_20of_20a_20dos_20utility [2018/03/31 13:19]
127.0.0.1 external edit
reading_20the_20exit_20code_20of_20a_20dos_20utility [2018/04/14 17:19] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Reading the exit code of a DOS utility===== =====Reading the exit code of a DOS utility=====
  
-//by Richard Russell, May 2006//\\ \\  BBC BASIC for Windows allows you to execute an external program using the ***RUN** command. The program can be a Windows //GUI program//, a Windows //console program// or an //MS-DOS program//. Both Windows console programs and MS-DOS programs have the ability to return an //exit code// which may, for example, indicate whether the program completed successfully or not. Listed below are three methods of discovering the exit code:\\ \\ +//by Richard Russell, May 2006//\\ \\  BBC BASIC for Windows allows you to execute an external program using the ***RUN** command. The program can be a Windows //GUI program//, a Windows //console program// or an //MS-DOS program//. Both Windows console programs and MS-DOS programs have the ability to return an //exit code// which may, for example, indicate whether the program completed successfully or not. Listed below are three methods of discovering the exit code: 
 + 
 ==== Method 1 ==== ==== Method 1 ====
-\\  ​The routine below allows the exit code to be discovered by running the external utility via a //batch file//:\\ \\ + 
 +The routine below allows the exit code to be discovered by running the external utility via a //batch file//: 
 + 
 +<code bb4w>
         F% = OPENOUT "​RUN.BAT"​         F% = OPENOUT "​RUN.BAT"​
         PRINT #F%, program$ : BPUT #F%,10         PRINT #F%, program$ : BPUT #F%,10
Line 13: Line 17:
         CLOSE #F%         CLOSE #F%
         exitcode% = VAL(exitcode$)         exitcode% = VAL(exitcode$)
 +</​code>​
 +
 The variable **program$** should contain the name of the external program plus any command line parameters it needs. Note that for this routine to execute correctly the //current directory// must be valid and writeable.\\ \\  Some standard DOS commands return exit codes which you may wish to test. For example the **XCOPY** command returns one of the following values:​\\ ​ The variable **program$** should contain the name of the external program plus any command line parameters it needs. Note that for this routine to execute correctly the //current directory// must be valid and writeable.\\ \\  Some standard DOS commands return exit codes which you may wish to test. For example the **XCOPY** command returns one of the following values:​\\ ​
  
Line 20: Line 26:
   * 4: There is not enough memory or disk space, or syntax error.   * 4: There is not enough memory or disk space, or syntax error.
   * 5: Disk write error occurred.   * 5: Disk write error occurred.
-\\ +
 ==== Method 2 ==== ==== Method 2 ====
-\\  ​Run the external program using the function **FNexecuteandwait** which is documented in the article [[/​Waiting%20for%20an%20external%20program%20to%20terminate|Waiting for an external program to terminate]] (scroll about two-thirds of the way down). The function returns the exit code.\\ \\ + 
 +Run the external program using the function **FNexecuteandwait** which is documented in the article [[/​Waiting%20for%20an%20external%20program%20to%20terminate|Waiting for an external program to terminate]] (scroll about two-thirds of the way down). The function returns the exit code. 
 ==== Method 3 ==== ==== Method 3 ====
-//by Jon Ripley, May 2006//\\ \\  ​Add code similar to the following to the initialisation routine of your program:\\ + 
 +by Jon Ripley, May 2006 
 + 
 +Add code similar to the following to the initialisation routine of your program: 
 + 
 +<code bb4w>
         SYS "​GetModuleHandle",​ "​MSVCRT.DLL"​ TO hdll%         SYS "​GetModuleHandle",​ "​MSVCRT.DLL"​ TO hdll%
         SYS "​GetProcAddress",​ hdll%, "​system"​ TO hsys%         SYS "​GetProcAddress",​ hdll%, "​system"​ TO hsys%
-Here **hdll%** the handle of the C run-time library used by the BBC BASIC interpreter and **hsys%** is a pointer to the //​system()//​ function the library provides.\\ \\  To execute a command anywhere in your program use code similar to the following:\\ +</​code>​ 
 + 
 +Here **hdll%** the handle of the C run-time library used by the BBC BASIC interpreter and **hsys%** is a pointer to the //​system()//​ function the library provides.\\ \\  To execute a command anywhere in your program use code similar to the following: 
 + 
 +<code bb4w>
         SYS hsys%, program$ TO exitcode%         SYS hsys%, program$ TO exitcode%
 +</​code>​
 +
 The variable **program$** should contain the name of the external program plus any command line parameters it needs. When the program returns **exitcode%** will contain the //exit code// of the program. The variable **program$** should contain the name of the external program plus any command line parameters it needs. When the program returns **exitcode%** will contain the //exit code// of the program.
reading_20the_20exit_20code_20of_20a_20dos_20utility.txt · Last modified: 2018/04/14 17:19 by richardrussell