So i am running into a problem using subprocess.call() and i think i may just be calling it wrong. I am using:
subprocess.call('testingosfile.py')
and i get the traceback:
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
subprocess.call('testingosfile.py')
File "C:\Python27\lib\subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
startupinfo)
WindowsError: [Error 193] %1 is not a valid Win32 application
and the contents of testingosfile.py is:
print "hello world!"
raw_input('....')
how do i manage to get this running?
Thank you in advance for your replies.
The error message makes perfect sense – with
subprocess, you can only start an executable. So, to fix it, you should start an executable. Specifically, you should start the Python interpreter and tell it to run your script. Something likeshould work, although you might have to provide the full path to the Python interpreter (I can’t test at the moment).
However, have you considered importing
testingosfile.pyinstead? Whenever you import a Python script, all the commands in that script are run. Usinginside a function in order to execute the commands would be poor style, but you could package up the useful commands of
testingosfile.pyinto some function. Then, you could useat the top of your main script, and just call that function whenever you want to print Hello World and get the user’s input.