Thank you Daryl for sharing it which is much helpful.
Original Message:
Sent: Dec 06, 2024 09:28 AM
From: Daryl Brown
Subject: Running 2 Command lines in a single Job.
This is all code that would be placed in the process tab. (The post process tab is best used for evaluating how everything played out on the Process tab, but not so useful for kicking off new scripts unless you want to use ACTIVATE_UC_OBJECT or PREP_PROCESS.)
So for windows, I would try something like this:
echo running command 1.
call command1.cmd
set retcode=%errorlevel%
echo return code = %retcode%
echo.
if %retcode% == 0 goto :run_command_1b
if %retcode% == 1 goto :run_command_2
goto :done
:data :run_command_1b
echo running command 1b.
call command1b.cmd
set retcode=%errorlevel%
echo return code = %retcode%
echo.
goto :done
:data :run_command_2
echo running command 2.
call command2.cmd
set retcode=%errorlevel%
echo return code = %retcode%
echo.
goto :done
:data :done
if not %retcode% == 0 goto :retcode
As before, you'll want to change the 'call command*.cmd' references to whatever your appropriate commands are.
Note that if you need to be able to figure out, for the sake of your overall workflow, which commands you actually ended up running (e.g., command 1 + command 1b vs command 1 + command 2), then that's the kind of thing you could use the Post Process tab for. You could use PREP_PROCESS_REPORT to analyze your report output and look for certain strings to confirm which scenario took place.
One other thing to be mindful of is when you combine a series of commands into a single job like this, it can make restarting the job more complicated (e.g., if you want to just restart command2 without having to rerun command1 again also). @Markus Embacher's suggestion about using an IF workflow is one way to address this...although that goes against your requirement to have everything contained in a single job. Another option would be to create restart points within your windows script -- check out the documentation on the :RESTART function to see if this might be useful.
Original Message:
Sent: Dec 05, 2024 06:50 PM
From: pavan shashikanth guddeti
Subject: Running 2 Command lines in a single Job.
Hi Daryl,
I made a wrong question earlier actually its 3 commands and its Windows Job.
If Command 1 returns return code as 0 then its needs to run one set of command.
If command 1 return return code as 1 then its needs to run one set of command.
Could you please Help me with you're Updated script.Thanks in Advance.
Original Message:
Sent: Dec 05, 2024 06:14 PM
From: Daryl Brown
Subject: Running 2 Command lines in a single Job.
Is this a unix job or windows job? It'll help in providing an example...
But for example, if it's unix:
echo "running command 1."
./command1.sh
retval=$?
echo "return code = $retval"
echo ""
if test $retval -eq 1
then
echo "command 1 failed. Running command 2."
./command2.sh
retval=$?
echo "return code = $retval"
fi
(exit $retval)
Obviously, you can replace './command1.sh' and './command2.sh' with whatever is appropriate in your case.
Original Message:
Sent: Dec 05, 2024 04:28 PM
From: pavan shashikanth guddeti
Subject: Running 2 Command lines in a single Job.
Hi All,
We're mainly trying to achieve out here is have 2 command lines in same Job and if 1st command line gets failed with Return code 1 then it needs to execute 2nd command line(either through Process or Post process) instead of running through another job.
Can some one help us out here. Thanks in Advance.