Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
シェル スクリプト内から Python スクリプトを呼び出しています。Python スクリプトは、失敗した場合にエラー コードを返します。
シェルスクリプトでこれらのエラーコードを処理し、必要に応じて終了するにはどうすればよいですか?
最後のコマンドの終了コードは に含まれてい$?ます。
$?
以下の疑似コードを使用します。
python myPythonScript.py ret=$? if [ $ret -ne 0 ]; then #Handle failure #exit if required fi
変数の$?ことですか?
$ python -c 'import foobar' > /dev/null Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named foobar $ echo $? 1 $ python -c 'import this' > /dev/null $ echo $? 0