更新时间:2023-12-04 10:39:10
shlex
并未执行您想要的操作:
shlex
is not doing what you want:
>>> list(shlex.shlex("/bin/ksh -c \". /Home/user/.khsrc\""))
['/', 'bin', '/', 'ksh', '-', 'c', '". /Home/user/.khsrc"']
您正在尝试执行根目录,但不允许这样做,因为它是目录而不是可执行文件.
You're trying to execute the root directory, and that is not allowed, since, well, it's a directory and not an executable.
相反,只需给subprocess.call列出程序名称和所有参数的列表即可:
Instead, just give subprocess.call a list of the program's name and all arguments:
import subprocess
command_line = ["/bin/ksh", "-c", "/Home/user/.khsrc"]
subprocess.call(command_line)