subprocess.call() throws exception

31 views
Skip to first unread message

Ulli Horlacher

unread,
Mar 26, 2025, 9:55:19 AMMar 26
to pyins...@googlegroups.com

I have a program which calls Windows CLI commands via subprocess.call():

import subprocess

def syscall(*cmd):
cmd = ['cmd','/d','/c']+list(cmd)
subprocess.call(cmd)

When I compile it with pyinstaller and start the executable via
desktop-click, it throws an exception:

Traceback (most recent call last):
File "\\VBOXSRV\python\W10\fexit_20250325_1641.py", line 3468, in <module> wexit(main())
File "\\VBOXSRV\python\W10\fexit_20250325_1641.py", line 281, in main menu()
File "\\VBOXSRV\python\W10\fexit_20250325_1641.py", line 376, in menu cls()
File "\\VBOXSRV\python\W10\fexit_20250325_1641.py", line 3366, in cls
syscall('cls')
File "\\VBOXSRV\python\W10\fexit_20250325_1641.py", line 3373, in syscall
subprocess.call(cmd)
File "subprocess.py", line 345, in call
File "subprocess.py", line 966, in __init__
File "subprocess.py", line 1435, in _execute_child
OSError: [WinError 740] The requested operation requires elevation

Why/which "elevation"?

There is no such error when I run this programm from a cmd.exe or
cygwin/bash window.

There is also no error when I I replace subprocess.call() with os.system()
but then I have to use a simple string as argument and cannot use a list of
strings.

I am using Windows 10 with:
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32

--
Ullrich Horlacher Server und Virtualisierung
Rechenzentrum TIK
Universitaet Stuttgart E-Mail: horl...@tik.uni-stuttgart.de
Allmandring 30a Tel: ++49-711-68565868
70569 Stuttgart (Germany) WWW: https://www.tik.uni-stuttgart.de/
REF:<20250325173...@tik.uni-stuttgart.de>

João Luis Valle

unread,
Mar 26, 2025, 11:25:17 AMMar 26
to pyins...@googlegroups.com
Thank you a lot!

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pyinstaller/20250325173136.GA433434%40tik.uni-stuttgart.de.

Chris Barker

unread,
Mar 26, 2025, 12:48:13 PMMar 26
to pyins...@googlegroups.com
the call command:

subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False, cwd=None, timeout=None, **other_popen_kwargs)

I do not understand the intricacies of subprocess, and even less so the Windows security model -- but I'd give a try to setting:

 shell=True

I *think* that will get it closer too what os.system() does.

Then look at popen, and see if any of the "other_popen_kwargs" might help.

(I do note that many of the Popen parameters are apparently "posix only" so ???


If that doesn't work, take a look at the subprocess docs, there are notes in there about replacing os.system.

-CHB




--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris....@noaa.gov
Reply all
Reply to author
Forward
0 new messages