Python Forum

Full Version: Upgrade makes Code Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i upgrade (Clean install) python from 3.9 to 3.10.5
and try this code
import subprocess
subprocess.call("title Test pause & Pause")
then it failed:
Error:
Traceback (most recent call last): File "C:\Users\GIGABYTE\Desktop\test.py", line 2, in <module> subprocess.call("title Test pause & Pause") File "C:\Python\Python310\lib\subprocess.py", line 345, in call with Popen(*popenargs, **kwargs) as p: File "C:\Python\Python310\lib\subprocess.py", line 969, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Python\Python310\lib\subprocess.py", line 1438, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] The system cannot find the file specified
any clue to fix this?
Try this perhaps
subprocess.call("title Test pause & Pause", shell=True)
If it works, read a tutorial about the subprocess module.
(Jul-28-2022, 04:58 PM)Gribouillis Wrote: [ -> ]Try this perhaps
subprocess.call("title Test pause & Pause", shell=True)
If it works, read a tutorial about the subprocess module.
thank for the reply,
now the error does not appear,
and sadly the cmd window does not appear too
I don't know the Windows OS, but you could perhaps call the 'cmd' command to open a cmd window, for example
subrocess.call(['cmd', '/k', 'title spam'])
or something similar.
You should be using subprocess.run() instead of subprocess.call(). Subprocess.call() is the old Python 2.7 way of doing things.

Upgrading is not the source of your problem. I get the same error running with Python 3.9.
(Jul-28-2022, 05:23 PM)Gribouillis Wrote: [ -> ]I don't know the Windows OS, but you could perhaps call the 'cmd' command to open a cmd window, for example
subrocess.call(['cmd', '/k', 'title spam'])
or something similar.
thank you, this the solution, I will give you a point
import subprocess
subprocess.call(['cmd', '/k', 'title Test pause & Pause & exit'])
(Jul-28-2022, 05:26 PM)deanhystad Wrote: [ -> ]You should be using subprocess.run() instead of subprocess.call(). Subprocess.call() is the old Python 2.7 way of doing things.

Upgrading is not the source of your problem. I get the same error running with Python 3.9.
thank you, the call and run give same result as run, I will give you point too
import subprocess
subprocess.run(['cmd', '/k', 'title Test pause & Pause & exit'])