-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Subprocess.run does not support commandline arguments, at least on Linux. The custom commands throw an exception. I Blender, nothing happens. This means that commands like shutdown now on linux do not work. I suspect that it may be similar on MacOS. I do not have tested this on windows but since that's what the default commands seem to be for I think it may work? subprocess.run seeks to execute a file, not a command like in a shell.
Consider instead launching a shell and letting the shell execute the input command. Like this:
subprocess.run(["bash", "-c", shutdown_command])Example:
import subprocess
shutdown_command = "touch ~/foo"
subprocess.run(shutdown_command)plex@apoapsis /tmp/tmp.qh8oaiT3bP % python a.py
Traceback (most recent call last):
File "/tmp/tmp.qh8oaiT3bP/a.py", line 4, in <module>
subprocess.run(shutdown_command)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/subprocess.py", line 554, in run
with Popen(*popenargs, **kwargs) as process:
~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/subprocess.py", line 1039, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass_fds, cwd, env,
^^^^^^^^^^^^^^^^^^^
...<5 lines>...
gid, gids, uid, umask,
^^^^^^^^^^^^^^^^^^^^^^
start_new_session, process_group)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/subprocess.py", line 1857, in _execute_child
self._posix_spawn(args, executable, env, restore_signals, close_fds,
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
p2cread, p2cwrite,
^^^^^^^^^^^^^^^^^^
c2pread, c2pwrite,
^^^^^^^^^^^^^^^^^^
errread, errwrite)
^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/subprocess.py", line 1801, in _posix_spawn
self.pid = os.posix_spawn(executable, args, env, **kwargs)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'touch ~/foo'
Metadata
Metadata
Assignees
Labels
No labels