|
Home > Archive > Unix Shell > April 2004 > Getting process error info
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Getting process error info
|
|
| D. Alvarado 2004-04-29, 11:34 am |
| Hi, I'm rather a novice to shell scripting, but I'm using /bin/sh, and
I'm trying to record the success of a process I run and then any error
message produced when the processes crashes. If it's useful, the
process I'm running is
java org.apache.xalan.xslt.Process -in $XML_INPUT_FILE -out
$XML_OUTPUT_FILE -xsl liml2html.xsl -xml
What is the recommended way of saving out success and/or error
information? Thanks, - Dave
| |
| Kevin Rodgers 2004-04-29, 12:35 pm |
| D. Alvarado wrote:
> Hi, I'm rather a novice to shell scripting, but I'm using /bin/sh, and
> I'm trying to record the success of a process I run and then any error
> message produced when the processes crashes. If it's useful, the
> process I'm running is
>
> Java org.apache.xalan.xslt.Process -in $XML_INPUT_FILE -out
> $XML_OUTPUT_FILE -xsl liml2html.xsl -xml
>
> What is the recommended way of saving out success and/or error
> information? Thanks, - Dave
>
If it's a well-behaved Unix process, it will return 0 as its exit status
when it succeeds and something else when it fails, and it will write any
error messages to file descriptor 2 (aka standard error). The exit
status is available in the special $? variable reference, but you can
test it directly in an if command:
if Java blah blah blah
then
# success
else
# failure
fi
I find it's usually best not to redirect error messages, so the user can
see them.
--
Kevin Rodgers
| |
| Barry Margolin 2004-04-29, 12:35 pm |
| In article <9fe1f2ad.0404290743.32c6300a@posting.google.com>,
laredotornado@zipmail.com (D. Alvarado) wrote:
> Hi, I'm rather a novice to shell scripting, but I'm using /bin/sh, and
> I'm trying to record the success of a process I run and then any error
> message produced when the processes crashes. If it's useful, the
> process I'm running is
>
> Java org.apache.xalan.xslt.Process -in $XML_INPUT_FILE -out
> $XML_OUTPUT_FILE -xsl liml2html.xsl -xml
>
> What is the recommended way of saving out success and/or error
> information? Thanks, - Dave
The variable $? contains the exit status of the last process; normally,
any value other than 0 indicates that it exited due to an error.
You can save the error messages by redirecting standard error:
<command> 2>errors.out
will run <command> with standard error put in the file errors.out.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Web Surfer 2004-04-29, 2:34 pm |
| [This followup was posted to comp.unix.shell]
In article <9fe1f2ad.0404290743.32c6300a@posting.google.com>,
laredotornado@zipmail.com says...
> Hi, I'm rather a novice to shell scripting, but I'm using /bin/sh, and
> I'm trying to record the success of a process I run and then any error
> message produced when the processes crashes. If it's useful, the
> process I'm running is
>
> Java org.apache.xalan.xslt.Process -in $XML_INPUT_FILE -out
> $XML_OUTPUT_FILE -xsl liml2html.xsl -xml
>
> What is the recommended way of saving out success and/or error
> information? Thanks, - Dave
>
By convention an exit status of zero from any program indicates success
and a non-zero exit status indicates a problem. The exit status of any
program run from a shell is saved in the shell variable $?. Note that
EVERY command that is run overwrites the value of $? , so you might want
to consider saving the value of $? in a named variable by doing
something like :
exit_status=$?
To save the error messages produced from a UNIX command you can do the
following :
some_command parm1 2>errors.log
|
|
|
|
|