I need the pid(process id) to kill the task afterwards. It's a OneNote file shortcut on my PC.
If I start with it shell=True, the pid from that isnt the same as the one in Task Manager, so this wont work:
os.chdir("E:\Anyagok\Programozás\Python\projekts\Én projektjeim")
am=subprocess.Popen("cold_turkey.url",shell=True)
os.system("TASKKILL /F /PID {}".format(am.pid))
So, first try:
os.chdir("E:\Anyagok\Programozás\Python\projekts\Én projektjeim")
subprocess.Popen("E:\Anyagok\Programozás\Python\projekts\Én projektjeim\cold_turkey.url")
Traceback (most recent call last):
File "<ipython-input-236-87374b9d7654>", line 1, in <module>
subprocess.Popen("E:\Anyagok\Programozás\Python\projekts\Én projektjeim\cold_turkey.url")
File "E:\Download\PROGIK\ANACONDA\lib\site-packages\spyder\utils\site\sitecustomize.py", line 210, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)
File "E:\Download\PROGIK\ANACONDA\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "E:\Download\PROGIK\ANACONDA\lib\subprocess.py", line 997, in _execute_child
startupinfo)
I have to open it without shell to get the proper pid, but I just cant open it.
1. method, just the link
subprocess.Popen("E:\Anyagok\Programozás\Python\projekts\Én projektjeim\cold_turkey.url")
WindowsError: [Error 193] %1 is not a valid Win32 application
method:
subprocess.Popen("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office 2016\OneNote 2016.lnk", "E:\Anyagok\Programozás\Python\projekts\Én projektjeim\cold_turkey.url") Traceback (most recent call last):
File "<ipython-input-238-80cb9d5ed425>", line 2, in <module> "E:\Anyagok\Programozás\Python\projekts\Én projektjeim\cold_turkey.url") File "E:\Download\PROGIK\ANACONDA\lib\site-packages\spyder\utils\site\sitecustomize.py", line 210, in __init__ super(SubprocessPopen, self).__init__(*args, **kwargs) File "E:\Download\PROGIK\ANACONDA\lib\subprocess.py", line 609, in __init__ raise TypeError("bufsize must be an integer") TypeError: bufsize must be an integer
How can it be opened with Popen() so that I can have the pid?
There has to be a better way than actually using This