在python上运行.sh脚本

时间:2019-05-20 18:40:02

标签: python-3.x shell automation

我正在尝试将shell脚本作为自动python的一部分运行,但出现此错误(如下所示):

Traceback (most recent call last):
  File "def3.py", line 68, in <module>
    shellscript = subprocess.Popen([sh_execute], stdin=subprocess.PIPE)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied:

我尝试了os.system(),它给出了权限被拒绝的错误 (我尝试使用#!/usr/bin/env python#!/usr/bin/python,但没有用)

 def get_directories(path):
     directories = [x for x in os.listdir(path)]  # 'directories' = x which is in the 'path'
     directories = [(path + x) for x in directories]  # now directories = x that x is x + path
 return directories

_dir = get_directories(dest)

for i in range(len(_dir)):
    sh_execute = _dir[i] + '/' + 'geo.sh'
    #os.system('sh ' +  sh_execute)

    shellscript = subprocess.Popen([sh_execute], stdin=subprocess.PIPE)
    shellscript.stdin.write("yes\n")
    shellscript.stdin.close()
    returncode = shellscript.wait()

0 个答案:

没有答案