[Tutor] help with erros using subprocess module
Jerome Jabson
jjabson at yahoo.com
Wed May 10 19:18:41 CEST 2006
Hi Bo,
Jerome Jabson 写é“:
> Hi,
>
> I've been trying to write a wrapper around some
shells
> scripts using the subprocess module. But I'm getting
> errors I quite don't know how to debug. I've only
been
> writing Python for a few months and starting
processes
> are new to me. Here's my code:
>
> import os
> import re
> import subprocess
>
> ####################
> #### Definition ####
> ####################
>
> def proc(cmd_in):
> cmd = cmd_in
> os.chdir("/home/qauser/jerome")
> outFile = os.path.join(os.curdir, "output.log")
> outptr = file(outFile, "w")
> errFile = os.path.join(os.curdir, "error.log")
> errptr = file(errFile, "w")
> retval = subprocess.call(cmd, 0, None, None,
> outptr, errptr)
> errptr.close()
> outptr.close()
> if not retval == 0:
> errptr = file(errFile, "r")
> errData = errptr.read()
> errptr.close()
> raise Exception("Error executing command: " +
> repr(errData))
>
> def setup():
> print "=== Starting Setup ==="
> proc("/home/qauser/jerome/qaSetup.sh")
> print "=== Setup Complete ==="
>
> def run_junit():
> file_in =
>
open("/home/qauser/automation/testdata/junit_master_file",
> "r")
>
Could you put the contents in the junit_master_file
here ?
Are the first field in every line where the cmd name
locates contain the
full path to the
command ?
Here is the content of the junit_master_file:
####################################################################
# This is the input file parameter for the JUnit test.
Here is how #
# the prameters are used:
#
#
#
# qaRun.sh <test_type> <testdata> <source> <dest>
#
#
#
# There are 3 different test_type:
#
# netmap_perf
#
# threatmap_perf
#
# netmap_func
#
####################################################################
netmap_func,/home/qauser/junit/static_nat/simple_nat,10.1.1.0,172.16.200.0
Basically once I have this running there will be 100s
of lines that map to the comma separated line. From
the comments you can tell what the qaRun.sh script is
looking for as far as params, and that's what this
file is for.
Thanks for your help!
Jerome
> match = re.compile('#+')
> work_list = []
> for line in file_in:
> work = line
> work = work.rstrip('\n')
> if match.search(work):
> found = False
> else:
> found = True
> if found == True:
> work_list = work.split(',')
> arg1 = work_list[0]
> arg2 = work_list[1]
> arg3 = work_list[2]
> arg4 = work_list[3]
> cmd = "/home/qauser/jerome/qaRun.sh %s %s
%s
> %s"
> cmdstr = cmd % (arg1,arg2,arg3,arg4)
> print "=== Starting JUnit Run ==="
> proc(cmdstr)
> print "=== JUnit Run Complete ==="
>
>
> ####################
> ###### Main ######
> ####################
>
> setup()
> run_junit()
>
> The setup() def seems to work great, but the
> run_junit() seems to have problems. I believe due to
> the params I'm passing. Here are the errors I'm
> getting:
>
> [qauser at gary automation]$ ./runJunit.py
> === Starting JUnit Run ===
> Traceback (most recent call last):
> File "/home/qauser/automation/runJunit.py", line
63,
> in ?
> run_junit()
> File "/home/qauser/automation/runJunit.py", line
54,
> in run_junit
> proc(cmdstr)
> File "/home/qauser/automation/runJunit.py", line
18,
> in proc
> retval = subprocess.call(cmd, 0, None, None,
> outptr, errptr)
> File
> "/opt/python-2.4.3/lib/python2.4/subprocess.py",
line
> 412, in call
> return Popen(*args, **kwargs).wait()
> File
> "/opt/python-2.4.3/lib/python2.4/subprocess.py",
line
> 542, in __init__
> errread, errwrite)
> File
> "/opt/python-2.4.3/lib/python2.4/subprocess.py",
line
> 975, in _execute_child
> raise child_exception
> OSError: [Errno 2] No such file or directory
>
> I can't seem to figure out what file or directory is
> missing.
>
> Your help is greatly appreciated,
> Jerome
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Tutor
mailing list