[英]Error when calling a python script from expect script
我有一个名为mypython.py的python脚本,其中导入了一个记录器模块。 从名为myexpect.exp的期望脚本中调用mypython.py。 我的问题是,当我在mypython.py中添加logger.info('test')语句并从myexpect.exp调用它时,myexpect.exp失败。 如果我用print语句替换logger.log('test')语句,那么它工作正常。
python脚本的内容
import os
import sys
import datetime
import time
import argparse
import logging
logging.basicConfig(format="%(asctime)s %(message)s",
datefmt='%m/%d/%Y %I:%M:%S %p',
level=logging.INFO)
logger = logging.getLogger(__name__)
***
***
def main():
args = get_args()
print 'This is from print statement ' + args.test_arg ### This is OK
logger.info("This is from logger statement" + " " + args.test_arg) ### This has issue
期望脚本的内容
#!/usr/bin/expect --
#exec python mypath/stratus/bin/mypython.py "test" ">@stdout"
exec python prnt_stmt.py -t arg_from_exp ">@stdout"
我得到的错误
This is from print statement arg_from_exp
03/06/2014 03:16:55 AM This is from logger statement arg_from_exp
while executing
"exec python mypython.py -t arg_from_exp ">@stdout""
(file "./myexpect.exp" line 9)
有人可以帮我吗?
Tcl的exec
命令有点奇怪。 如果它会抛出一个错误
请参阅http://wiki.tcl.tk/exec的“子状态”部分
您可以这样做:
set status [catch {exec -ignorestderr python mypython.py -t arg_from_exp} output]
if {$status == 0} {
puts "no problem"
} else {
puts "non-zero exit status"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.