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.