python os.system保存返回值_Python中os.system()的返回值是多少?

os.system('command')返回一个16位数字,从左开始的前8位(lsb)表示操作系统用来关闭命令的信号,接下来的8位表示命令的返回代码。00000000 00000000

exit code signal num

示例1-命令退出,代码为1os.system('command') #it returns 256

256 in 16 bits - 00000001 00000000

Exit code is 00000001 which means 1

示例2-命令退出,代码为3os.system('command') # it returns 768

768 in 16 bits - 00000011 00000000

Exit code is 00000011 which means 3

现在试试信号-

示例3-编写一个长时间睡眠的程序,在os.system()中将其用作命令,然后通过kill-15或kill-9终止它os.system('command') #it returns signal num by which it is killed

15 in bits - 00000000 00001111

Signal num is 00001111 which means 15

可以将python程序设置为command='python command.py'import sys

sys.exit(n) # here n would be exit code

对于c或c++程序,可以使用return from main()或exit(n)from any function#

注意-这适用于unixOn Unix,

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值