1

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.

2 Answers 2

2

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 like

subprocess.call(['python.exe', 'testingosfile.py'])

should 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.py instead? Whenever you import a Python script, all the commands in that script are run. Using

import testingosfile

inside a function in order to execute the commands would be poor style, but you could package up the useful commands of testingosfile.py into some function. Then, you could use

import testingosfile

at the top of your main script, and just call that function whenever you want to print Hello World and get the user's input.

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

1 Comment

Great! it works! :D (although you would indeed have to provide the full path to the interpreter if you dont have it in your PATH) Thank you so much!
1

try subprocess.call("myfile.ext", shell=True)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.