如何从Python获取退出代码? [英] How to get exit code from Python?

查看:479
本文介绍了如何从Python获取退出代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python代码。我使用cmd文件来执行我的python代码。在cmd文件中,我将从我的python代码中获取errorlevel。



我尝试过:



 infile =FeatureByte.txt
数组= [6J,yB,ss,11]

with open(infile,r)as input_file:
output_list = []
for rec in input_file.read()。splitlines():
rec = rec [: -3]
FBlist = [rec [i:i + 2] for i in range(0,len(rec),2)]
output_list.append(FBlist)
print(output_list )

FBlist_set = set(FBlist)
Array_set = set(Array)

如果是Array_set& FBlist_set:
print(Found)
exit(0)
else:
print(Not Found)
exit(1)

 set logfile = C :\ Users \Log.txt 
set PYTHONPATH =C:\ Users \ AppData \ Local \Programs\Python\Python37-32
set PYTHONEXE =%PYTHONPATH %\ _Python -B


C:\ Users \ AppData \ Local \Programs\Python\Python37-32\python.exe-BC :\ Users \Desktop \Pyth.py

echo%ERRORLEVEL%>> %logfile%

从这两个代码中,我总是在我的Log.txt文件中得到1。

解决方案

检查:从中获取退出代码使用Python的批处理文件 - Stack Overflow [ ^ ]


I have a python code. I use cmd file to execute my python code. In the cmd file, I am going to get errorlevel from my python code.

What I have tried:

infile = "FeatureByte.txt"
Array = ["6J", "yB", "ss", "11"]

with open(infile, "r") as input_file:
	output_list = []
	for rec in input_file.read().splitlines():
	   rec = rec[:-3]  
	   FBlist = [rec[i:i+2] for i in range(0, len(rec), 2)] 
	   output_list.append(FBlist)
	   print(output_list)

FBlist_set = set(FBlist)
Array_set = set (Array)

if Array_set & FBlist_set:
	print ("Found")
	exit(0)
else:
	print ("Not Found")
exit(1)




This is my cmd file :

set logfile=C:\Users\Log.txt
set PYTHONPATH="C:\Users\AppData\Local\Programs\Python\Python37-32"
set PYTHONEXE="%PYTHONPATH%\Python -B"


"C:\Users\AppData\Local\Programs\Python\Python37-32\python.exe" -B C:\Users\Desktop\Pyth.py

echo %ERRORLEVEL% >> "%logfile%"

From these both code, I always get 1 inside my Log.txt file.

解决方案

Check this: Get the exit code from a Batch file using Python - Stack Overflow[^]


这篇关于如何从Python获取退出代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆