0

Currently I am testing a very simple piece of code. I simply want to write a python script that sets a variable and then pass that variable into a bash script for use.

Python Script:

from subprocess import check_call
a = str(3)
check_call(["/home/desktop/bash2pyTest/test.sh", a], shell=False)

Bash Script:

#!/bin/bash
echo "This number was sent from the py script: " $1

I have read other Q&As that are related to this topic; however, I am not finding a solution that I am conceptually understand; thus, the syntax above might be incorrect. I have tried a few other methods as well; however, I keep receiving the following error:

Traceback (most recent call last):
  File "/home/cassandra/desktop/bash2pyTest/callVar.py", line 3, in <module>
    check_call(["/home/cassandra/desktop/bash2pyTest/test.sh", a],    shell=False)
  File "/usr/lib64/python2.7/subprocess.py", line 537, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 524, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 13] Permission denied

Process finished with exit code 1

Any help would be greatly appreciated. I'm stumped.

Community
  • 1
  • 1

2 Answers2

2

Try

chmod +x /home/desktop/bash2pyTest/test.sh

in shell. The file you are trying to execute is not executable.

Or another option in python script:

check_call(["sh","/home/desktop/bash2pyTest/test.sh", a], shell=False)
obayhan
  • 1,636
  • 18
  • 35
0

The error says that permission is denied. I tested your code, and it works fine on my machine. However, you will need to be sure that the user running the command has sufficient privileges for the test.sh script. Most importantly, be sure that test.sh has execute permissions set. That's often the most easily missed permission.

DKing
  • 574
  • 5
  • 16