Hi @Rory_Feng ,
Welcome to Microsoft Q&A! Apologies for the delayed response.
I did some tests with the provided scripts and was not able to find a direct way to get the exit code. However, using a driver script (which calls the test.sh
script above), we can get the exit code by using $?
- exit status of last operation. In my test, I placed the driver.sh in the /tmp directory and its content is:
/bin/bash /tmp/test.sh
ret=$?
echo $ret
In the PowerShell Automation script, the script being called is /tmp/driver.sh. And I can get the result as below:
#To retrieve the output/result back.
$result = $response.Content | convertfrom-json
$result.properties.output.value.message
Here, result.properties.output.value.message contains the complete output of that session in which the script executed, which is as below:
Enable succeeded:
[stdout]
there is no directory #---echo message
9 #---Exit status when calling /temp/test.sh
[stderr] #---Any message in error stream will be below this line
Please let me know if you have any questions.
---
Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.