首页 > 解决方案 > 有没有办法在 python 中使用带有 subprocess.call() 的 shell 脚本

问题描述

我在下面找不到此问题代码的解决方案:

import subprocess
subprocess.call(['./eu_presun.sh'])

shell 脚本与 main.py 在同一个目录中,我将使用 python,然后我想使用这个 shell 脚本,我收到了这个错误。

Traceback (most recent call last):
  File "~/_main.py", line 304, in <module>
    subprocess.call(['sh eu_presun.sh'])
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: './eu_presun.sh'

标签: python-3.xshellsubprocess

解决方案


好吧,我有点累了 答案是

subprocess.call(['./eu_presun.sh']**,shell=True**)

我也有这个地址的问题,我不得不添加完整路径


推荐阅读