User Tools

Site Tools


returning_20errors_20from_20windows_20commands

Differences

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

Link to this comparison view

returning_20errors_20from_20windows_20commands [2018/03/31 13:19]
127.0.0.1 external edit
returning_20errors_20from_20windows_20commands [2018/04/14 17:22] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Returning errors from Windows commands===== =====Returning errors from Windows commands=====
  
-//by Jonathan Harston, August 2010//\\ \\  The OSCLI command can be used to execute a Windows command. However, if the command fails, no error is generated, the Windows command interpreter merely //​displays//​ an error message. You may see this appearing in a DOS command box before it quickly disappears.\\ \\  However, the Windows command interpreter and properly-written commands output error message to the //​standard-error//​ output stream. This can be redirected to a file, and then any contents examined later. The following function does this.\\ \\ +//by Jonathan Harston, August 2010//\\ \\  The OSCLI command can be used to execute a Windows command. However, if the command fails, no error is generated, the Windows command interpreter merely //​displays//​ an error message. You may see this appearing in a DOS command box before it quickly disappears.\\ \\  However, the Windows command interpreter and properly-written commands output error message to the //​standard-error//​ output stream. This can be redirected to a file, and then any contents examined later. The following function does this. 
 + 
 +<code bb4w> ​
         DEF FNwin_cmd(cli$)         DEF FNwin_cmd(cli$)
         LOCAL ch%,​err$,​tmp$:​tmp$=@tmp$+STR$TIME         LOCAL ch%,​err$,​tmp$:​tmp$=@tmp$+STR$TIME
Line 8: Line 10:
         err$=GET$#​ch%:​CLOSE#​ch%:​OS."​Delete "+tmp$         err$=GET$#​ch%:​CLOSE#​ch%:​OS."​Delete "+tmp$
         =err$         =err$
-\\  ​This redirects the error output to a file, then reads that file to see if anything has been output to it. Bear in mind that if the called command displays its error reports to //​standard-out//​ instead of //​standard-error//,​ then it will return an empty string.\\ \\ +</​code>​ 
 + 
 +This redirects the error output to a file, then reads that file to see if anything has been output to it. Bear in mind that if the called command displays its error reports to //​standard-out//​ instead of //​standard-error//,​ then it will return an empty string. 
 ===== Examples ===== ===== Examples =====
 +<​code>​
       >PRINT FNwin_cmd("​junk"​)       >PRINT FNwin_cmd("​junk"​)
       '​junk'​ is not recognised as an internal or external command.       '​junk'​ is not recognised as an internal or external command.
Line 15: Line 21:
  
       >       >
-\\  ​Note that, as opposed to OSCLI itself, the command is //always// passed to Windows. In the second example above, the Windows **DIR** command is executed, which will result in a directory listing appearing in a DOS command box before quickly ​diappearing.\\ \\ +</​code>​ 
 + 
 +Note that, as opposed to OSCLI itself, the command is //always// passed to Windows. In the second example above, the Windows **DIR** command is executed, which will result in a directory listing appearing in a DOS command box before quickly ​disappearing. 
 ===== References ===== ===== References =====
  
   * http://​rtrussell.co.uk/​bbcwin/​manual/​bbcwin8.html#​opsys   * http://​rtrussell.co.uk/​bbcwin/​manual/​bbcwin8.html#​opsys
returning_20errors_20from_20windows_20commands.txt · Last modified: 2018/04/14 17:22 by richardrussell