![]() ![]() Set exitCode to do shell script "ps -A | grep -v grep | grep -q httpd echo $?" The other approach, which works if you want to capture the exit code is something like this: Normally do shell script will return stdout (the output of the command) rather than just the error code, but in this case grep's output would be empty since the text doesn't exist Note that this approach is somewhat peculiar to grep, since it returns an exit code that you're trying to respond to. If grep fails (it can't find the text) it returns an exit code that triggers the 'on error' block. If it succeeds (grep finds the text) then it displays the 'HTTPD is running' dialog. i.e., in this case, if grep returns 1 (not found)ĭisplay dialog "Status Is 1 (httpd not running)" we get here if the previous command fails If you want to catch the error code, the easiest way is via a try statement:ĭo shell script "ps -A | grep -v grep | grep httpd" In do shell script's case, an exit code of 1 is an error, and so it stops the script to report the error. However, grep returns a different status code - 1 if no lines were found. The issue is that do shell script always, always, always expects an exit status of 0 (success). You're dealing with your exit status incorrectly. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |