trying to create a test file to run two processes simultaneously. Using the subprocess module to do so. Having an issue where it says the file cannot be found, but it does not specify which file. We are using absolute filenames and can confirm that the path is correct. Can anyone tell us what this obscurity may be?
import subprocess
import random
port_num = random.randint(1049, 2000) # generates random port number
fns = open("filenames.txt").readlines() #reads in the file names
port_str = str(port_num)
for fn in fns:
fn_nospace = fn.strip() #remove any excess spaces
print fn_nospace
cwdhalf = ['pwd']
subprocess.call(cwdhalf)
cmd1 = ['./webserver.py '+port_str] # open webserver with the input portnumber
subprocess.check_call(cmd1) # calls cmd1
cmd2 = ['wget localhost:'+port_str+'/'+fn_nospace] # samething with wget, only this time using the filename
subprocess.check_call(cmd2)
The error being reported is as follows:
Traceback (most recent call last):
File "testwebserver.py", line 26, in <module>
subprocess.check_call(cmd1) # calls cmd1
File "/usr/lib/python2.6/subprocess.py", line 493, in check_call
retcode = call(*popenargs, **kwargs)
File "/usr/lib/python2.6/subprocess.py", line 480, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
The traceback shows that the issue is with cmd1
. Both commands in the code are incorrect.
The rule is simple: one list item -- one command-line parameter:
cmd1 = ['./webserver.py', port_str]
cmd2 = ['wget', 'localhost:%s/%s' % (port_str, fn_nospace)]
Also, OSError has filename
, filename2
attributes that you can inspect programmatically. Though they are not set in this case.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments