python回声程序是什么_回声$?从python - python

你好,我正在尝试从其他脚本调用的外部python脚本取回结果(我知道是1)。什么时候回声$?从命令行我得到1,但是当我尝试调用echo $?从python获取python脚本的结果,我在脚本中得到0。这是我的代码:

os.system(pythonPath+"serialWait.py "+dev+" "+brate+" login") //this

os.system(pythonPath+"serialCommand.py "+dev+" "+brate+" reset") //this works

value = subprocess.call('echo $?', shell=True)

>//here is where my issue lies I am trying to call the exit code from the previous python script but only get the true value from terminal

参考方案

这是不可能的:$?是仅在单个shell期间存在的变量。每次调用os.system()时,都会创建一个新的外壳:旧外壳已经退出,因此该外壳内部的变量(例如$?)不再存在。

请使用subprocess模块:

p1 = subprocess.Popen(['serialWait.py', dev, brate, 'login'])

p1.wait()

if p1.returncode != 0:

print 'Proc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值