我有python程序,它從shell運行。 當python出現錯誤時,它會退出(1)或其他內容,並且我需要shell程序才能得到該答案,如果出現錯誤,請再次運行此程序。在shell中獲取從Python退出(1)
-1
A
回答
1
退出代碼可以在$找到?看下面的例子:
python yourprogram.py
if [[ $? != 0 ]] ; then
dosomething
fi
1
在這種情況下,Python沒有什麼特別之處。您捕捉退出代碼與其他任何程序:
- 要麼你評估
$?
,你直接擁有這些代碼,如sanyi's answer,或 你嵌入程序調用在
if
或while
條件,其中其非零岬檢查:if ! python yourprogram.py; then dosomething fi
+0
當我搜索這個,在大多數地方他們從python調用shell腳本,並且它不是我的項目的好解決方案。而且我對shell腳本沒有太多的經驗。 –
相關問題
- 1. 從python退出shell腳本
- 2. 用Python獲取shell輸出?
- 3. make -e只能從子shell中退出
- 4. 不從shell腳本中退出
- 5. 從Python腳本獲取退出代碼與重定向輸出
- 6. Python:獲取shell命令的輸出'history'
- 7. 獲取python程序的退出代碼
- 8. Python Pexpect pxssh獲取退出狀態
- 9. 獲取shell腳本的退出碼在一個「陷阱EXIT」
- 10. 如何讓退出shell的Python腳本退出?
- 11. Python CMD模塊:Shell退出後-h
- 12. 從shell調用python並捕獲輸出
- 13. 如何在Python中獲取shell提示
- 14. 如何從Control-M執行時從Power Shell獲取退出代碼
- 15. 從標準輸入獲取python退格?
- 16. 如何在Python cmd shell中獲取異步輸出?
- 17. shell腳本退出
- 18. 如何在shell中獲取java輸出
- 19. 在Python中獲取前一個命令的退出代碼?
- 20. 在Python腳本中獲取最後命令的退出狀態
- 21. 無法獲取從python運行的shell腳本輸出
- 22. 從子shell腳本中的函數退出到父shell腳本
- 23. 獲取不在表中退出的id_customer
- 24. 在shell腳本中處理由python返回的退出代碼
- 25. 在python中從shell命令獲取返回值
- 26. 從shell命令定時退出
- 27. Shell腳本調用vim編輯器,獲取退出方法
- 28. shell - 獲取後臺進程的退出代碼
- 29. 如何獲取shell命令的退出狀態[在C中通過system()運行)?
- 30. 如何在Java中捕獲shell命令的退出狀態?
你在寫shell腳本嗎? – user2357112
兩者,python程序和shell腳本 –
是的,但真正的問題是關於shell腳本。 – glglgl