我有一个名为mypython.py的python脚本,它导入了一个记录器模块。 mypython.py是从名为myexpect.exp的expect脚本调用的。我的问题是当我在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)
任何人都可以帮助我吗?
答案 0 :(得分:4)
Tcl的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"
}