我正在Linux中使用python开发一个小工具。之前我使用的是Python 2.7,但现在我将其更改为Python 3.4以查看它是否可以帮助解决我的问题。当我给下面的代码:无法在子流程命令中使用shell = True时运行命令
try:
x=subprocess.check_output(command, shell=True, timeout=3)
except subprocess.TimeoutExpired as exc:
print ("Timeout bro")
exit()
except Exception as e:
msg = "Some issues in fetching details"
print (msg)
由于命令从其他设备获取详细信息和设备工作不正常,这是越来越后3秒超时和打印消息“超时兄弟”。我使用shell = True读取了安全问题,因此我将它作为shell = False一次,第二次删除了该参数。
try:
x=subprocess.check_output(command, shell=False, timeout=3)
except subprocess.TimeoutExpired as exc:
print ("Timeout bro")
exit()
except Exception as e:
msg = "Some issues in fetching details"
print (msg)
我在不同的地方看过,这个命令和shell = False一样工作得很好。但是,只要我用shell=False
运行上面的代码,代码直接打印“取得细节时的一些问题”,而不用等待3秒。有没有什么办法可以在没有shell = True的情况下运行代码?请帮忙。谢谢!
命令是什么? –
另外shell = False是默认的,所以你不需要传递它。 –