python3 subprocess.check_output的使用

python3 subprocess.check_output的使用,第1张

1.timeout参数不能和shell=True一起使用,不然就算是时间到了,还是会继续执行,等执行结束以后才会抛出subprocess.TimeoutExpired异常,timeout的单位是秒。

2.check_output返回的是子程序的执行结果(上述demo返回的就应该是helo),也是unicode编码,如果程序执行报错的话,会直接抛出异常CalledProcessError,并且异常当中会有output属性,该属性为unicode编码的,要当字符串使用的时候需要转码,如e.output.decode(encoding="utf-8")

3.想要执行的命令command_line不能有类似<的重定向符号,会报错。

1.增加子程序的监视开关

subout_flg : 0 #Subprogram Status

2.增加错误提示信息

ssubwarn"WARNING - THIS PROGRAM SUBPROGRAM IS ON"

3.增加命令块

psub_check #Sub Program Check

#if subprg$ = yes, result = mprint(ssubwarn)

if subout_flg = 1,

[

result = mprint(ssubwarn)

*sm00, "(", "OPERATION : ",35, *op_number, ")", e

*sm00, "(", ssubwarn, ")", e

ppost_real

]

ppost_real #Remove Program

exitpost

4.增加系统预处理及预读参数

pparameter # Run parameter table

if prmcode = 15378, subout_flg = rpar(sparameter,1)

pwrttparam #Information from parameters

if prmcode = 15378,

[

subout_flg = 1

]

5.在plinout下面条用刚刚新建的命令快

psub_check

6.测试结果

mastercam X及以上版本后处理代码

1.增加子程序的监视开关

subout_flg : 0 #Subprogram Status

2.增加错误提示信息

ssubwarn: "WARNING - THIS PROGRAM SUBPROGRAM IS ON"


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11286574.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存