batch file 和 python的溝通

一直在尋找windows 的batch file跟python溝通的方法
因為公司的產線,是用batch file 呼叫 exe 檔,根據回應的errorlevel來判定pass / fail
所以我認為,要先導入python到產線時,首先要把 errorlevel的部分搞定

google後查到,python內建的sys module有一個exit()符合我的需求

首先
寫下一個batch file呼叫python code

::test.bat
python test.py
echo %errorlevel%


再來寫一個python code
::test.py
import sys
print 'return error level as 2'
exit(2)

然後執行test.py , 你就會發現回傳的errorlevel是2了

留言

這個網誌中的熱門文章

如何在VS2022 Community 簡要的設定UDK2018的環境

自製讀取 H 檔案並找出 define 的程式

如何Build UDK2018