有没有一种方法可以在python内部使用带有subprocess.call()的shell脚本

时间:2020-02-25 21:02:36

标签: python-3.x shell subprocess

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

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'

1 个答案:

答案 0 :(得分:-1)

欧基我有点累 答案是

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

我对此地址也有疑问,我必须添加完整路径