0

I'm trying to run a shell script as part of automated python but I got this error (in below):

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:

I have tried with os.system() which gives permission denied errors (I tried with #!/usr/bin/env python and #!/usr/bin/python but didn't work)

 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()
DYZ
  • 55,249
  • 10
  • 64
  • 93
DGKang
  • 172
  • 1
  • 13
  • Is the script executable? Is the `x` permission bit set? – DYZ May 20 '19 at 18:46
  • Possible duplicate of [Can't execute shell script from python subprocess: permission denied](https://stackoverflow.com/questions/20291543/cant-execute-shell-script-from-python-subprocess-permission-denied) – DYZ May 20 '19 at 18:46
  • @DYZ Yes, it is executable. I tried the sh script on terminal. what is X permision? – DGKang May 20 '19 at 18:52
  • @DYZ where do I have to insert the line (chmod +x run.sh) in the script. Thank you for your kind comment. (I'm very new to Python...) – DGKang May 20 '19 at 18:53
  • You do not insert that line. You execute it on the command line to make the script executable. – DYZ May 20 '19 at 19:00
  • @DonggiKang : If you get _permission denied_, you should also post the permissions of the script. – user1934428 May 21 '19 at 06:38

0 Answers0