Absent Member.. Absent Member..
Absent Member..

ssh command stderr, stdout and exit code



I'm trying to capture standard error, standard out and the exit code of a unix program in an SSH Command flow step.  Here's my unix script for testing:



echo "standard out"
echo "standard error" >&2

exit 7

 The script executes fine using the SSH Command step, but the results are munged.  Here's the raw result:


{returnCode=-1;STDERR=;returnResult=;Result=;sessionId=iconclude4728939292462036583;STDOUT=standard out
standard error

 You can see that the Result and returnResult are blank and the standard error was combined with standard out.  The error code (7) is nowhere to be seen.  I have a unix process that returns error codes from 0 - 255 and different action needs to be taken based on the error code combined with standard error.


This is with OO version 9.0.7


Tags (2)
1 Reply
Absent Member.. Absent Member..
Absent Member..


Ok, I solved my own problem by writing a wrapper script that returns easily parseable XML.  There are probably a thousand ways to do this and mine is not the most elegant, robust or complex.  But, it works for me.


Filename: oowrap.sh


# Wrapper script for running unix commands from HPOO Flow.
#  - Returns easily parseable XML.
#  - Separates STDOUT and STDERR.
#  - Captures process id numbers.
#  - Captures exit code.
# Useage:
#  oowrap.sh /path/to/command -any -argument -you -want

progname=`echo $1 | awk -F\/ '{ print $NF }'`

$* 2>$stderr 1>$stdout &
wait $cmdpid

cat - << XML
<exec bashversion="$BASH_VERSION">
cat $stdout
cat - << XML
cat $stderr
cat - << XML

rm $stderr
rm $stdout

if [ $exitval -ne 0 ]
        exit 1


Using this is simple enough, just apply the "XML Get Element Value" result filter to the stdout result.



It seems to me like it would be easy to include this functionality in the "SSH Command" flow step, would be a lot cleaner than what I'm having to do here.


Tags (2)
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.