[Tutor] help with erros using subprocess module

Jerome Jabson jjabson at yahoo.com
Wed May 10 01:06:09 CEST 2006


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")
   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