2

I have a python script called mypython.py which has a logger module imported. The mypython.py is called from an expect script called myexpect.exp. My issue is when I add a logger.info('test') statement in mypython.py and call it from myexpect.exp then the myexpect.exp fails. If I replace the logger.log('test') statement with print statement then it is working fine.

Content of python script

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

Content of Expect Script

#!/usr/bin/expect --

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

Error which i got

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)

Can anyone help me out in this?

user3021774
  • 21
  • 1
  • 4

1 Answers1

4

Tcl's exec command is a bit weird. It will throw an error if

  1. the exec'ed command returns a non-zero exit status, or
  2. the exec'ed command writes to stderr.

See the "Child Status" section of http://wiki.tcl.tk/exec

You might do:

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"
}
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
glenn jackman
  • 238,783
  • 38
  • 220
  • 352