I have a Python file, which I want to open, keep open for 5 seconds, and then close it, and then repeat. I am using Python Subprocess for this, using the following code:
import subprocess
import time
import sys
p = subprocess.Popen("pagekite.py")
time.sleep(4)
p.terminate()
However, it gives me the following error:
Traceback (most recent call last):
File "C:/Users/ozark/Desktop/Savir/Programming/Choonka/closetry.py", line 5, in <module>
p = subprocess.Popen("pagekite.py")
File "C:\Users\ozark\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in
__init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\ozark\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in
_execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application
It seems only executables can be opened using this method? Then how do I do the same thing for a Python file? Any help will be appreciated. Thanks in advance.
MODIFICATIONS: I am now using subprocess.call('start pagekite.py', shell=True). How do I terminate this? Thanks.
pythoninterpreter, and give your script as an argument. As the error says, you can't directly run a Python script. Are you sure what you're trying to do can't be achieved through just importing the other script though?importthe script, are you sure it can execute it? Fixing it so you can import it is usually the best solution.pythonbefore the script name when you try to execute it, but this is less commonly done than on Unix-like platforms; the simple and portable solution is to spell outpython.