2014-03-06 22 views
2

로거 모듈을 가져온 mypython.py라는 python 스크립트가 있습니다. mypython.py는 myexpect.exp라는 expect 스크립트에서 호출됩니다. 내 문제는 mypython.py에 logger.info ('test') 문을 추가하고 myexpect.exp에서 호출하면 myexpect.exp가 실패합니다. logger.log ('test') 문을 print 문으로 대체하면 올바르게 작동합니다. 내가예상 스크립트에서 파이썬 스크립트를 호출 할 때 오류가 발생했습니다.

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) 

이 사람이 나를 도울 수있어 기대 스크립트

#!/usr/bin/expect -- 

#exec python mypath/stratus/bin/mypython.py "test" ">@stdout" 
exec python prnt_stmt.py -t arg_from_exp ">@stdout" 

오류의 파이썬 스크립트의

내용

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 

내용?

+0

왜 당신은 파이썬에서 모든 것을 쓰지 않는다? – Keith

답변

4

Tcl의 exec 명령이 약간 이상합니다.

  1. exec 된 명령이 0이 아닌 종료 상태를 반환하는 경우이 오류가 발생합니다, 또는
  2. exec 된 명령은 stderr에 기록합니다.

당신은 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" 
} 
관련 문제