1

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))
3
  • 1
    And which line causes that error? Commented Dec 18, 2009 at 9:56
  • 3
    Please provide the actual error traceback with the actual error message. Commented Dec 18, 2009 at 11:19
  • 1
    What is this "si" program? It looks suspicious that it is using a Windows file name E:/project.pj inside a Linux script. Is it a shell script, or an executable program? Commented Dec 18, 2009 at 14:16

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

5 Comments

wouldn't in that case an error have occurred before when trying to open errFile for writing?
"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.
Exactly. So if no such write error occurred, why would it not be able to find the file as you suggested?
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 ;)
yes, it could be error from si createsandbox, and even "si" not exists or unable to run.
0

try modify like this:

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

I guset subprocess.call will think that the first parameter which in "" is a command

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.