Page 1 of 1

Reading From Command Line Errors

PostPosted: Fri Aug 19, 2016 5:43 pm
by krackerjaxz
While I'm familiar with NeoBook being able to use the Windows Command Line as well as being able to run local applications via the command line, I'm curious as to whether a NeoBook application can also obtain information from the command line. For example, if I ran the DOS command of "del c:\jkaslfkjslafjs.xyz" then the command line would normally return the error of "Could Not Find c:\jkaslfkjslafjs.xyz" In such a case, is there a way for a NeoBook app to retrieve any error thrown by the command line or the dos-based application?

Re: Reading From Command Line Errors

PostPosted: Fri Aug 19, 2016 6:21 pm
by Gaev
krackerjaxz:

Say you want to run a command like dir notexist.txt ... code your NeoBook command like so ...
Code: Select all
Run "dir" "notexist.txt 2> err.txt" "Normal" "ReadErrorFile" ""

... note that ...

a) 2> err.txt will direct STDERR messages to the file named err.txt ... for further info see https://support.microsoft.com/en-ca/kb/110930

b) ReadErrorFile is the name of a subroutine that will be serviced when your Run command is completed ... you can use this to read the contents of the error file ... like so ...
Code: Select all
:ReadErrorFile
FileRead "err.txt" "All" "[ErrorFileContent]"
AlertBox "Error File Content" "[ErrorFileContent]"
Return
... this is just a "proof of concept" ... you might want to first check for presence of any errors ... and perhaps not need the AlertBox as I have used.

Re: Reading From Command Line Errors

PostPosted: Fri Aug 19, 2016 8:08 pm
by krackerjaxz
Awesome! Thanks for the info. I'm going to try to see if I can get it to assign the error message to a string (i.e. variable) and then have the Simple Text content to be the information that the variable contains (i.e. error message).