tags:

views:

217

answers:

1

Hello,

I am trying to write this script to my linux terminal and I am recieving the following error message: "OSError: [Errno 2] No such file or directory". Can anyone help, Thanks

#!/home/build/test/Python-2.6.4

import os, subprocess

   # Create a long command line
cmd =[\
 "si createsandbox --yes --hostname=be", \
 " --port=70", \
 " --user=gh", \
 " --password=34", \
 "  --populate --project=e:/project.pj", \
 " --lineTerminator=lf new_sandbox"\
 ]

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))
+2  A: 

If the error is in your script, May be you got error on this line

errptr = file(errFile, "r")

you can do like

if os.path.exists(errFile):
  errptr = file(errFile, "r")
  errData = errptr.read()
  errptr.close()
  raise Exception("Error executing command: " + repr(errData))

And also try with fullpath for command "si" like /usr/bin/si instead of just si

S.Mark
wouldn't in that case an error have occurred before when trying to open errFile for writing?
catchmeifyoutry
"w" in file(errFile, "w") will create new file or overwrite existing file, if file isn't able to write, you should get write error or something like that.
S.Mark
Exactly. So if no such write error occurred, why would it not be able to find the file as you suggested?
catchmeifyoutry
Coming to think of it, maybe it could just as well be a side effect from the external "si createsandbox" command.In any case, it's of course wise to test if the file exists, even though it's not obvious that it doesn't, but the exception should be raised independently of the file's existence ;)
catchmeifyoutry
yes, it could be error from si createsandbox, and even "si" not exists or unable to run.
S.Mark