Can't open sh file
18,949
Solution 1
I do not believe this would run from the terminal either because you must run the file in order. Try:
os.system('sh chmod +x run.sh|./run.sh')
instead.
See: https://askubuntu.com/questions/38661/how-do-i-run-sh-files for details on running sh files and how to use os.system() in python for running an shell order for the use of |
running in an order in a shell.
Solution 2
Make sure that your bash script has the right permissions (i.e it is executable). In a terminal run:
chmod +x run.sh
and then try (assuming that run.sh
is in the same directory as your python script)
import os
os.system('./run.sh')
Related videos on Youtube
Author by
R.Anchieta
Updated on June 04, 2022Comments
-
R.Anchieta almost 2 years
I'm trying to execute a sh file from script python.
My script python
os.system('sh run.sh')
My sh file
echo 'The house is blue' | /opt/palavras/por.pl > output.txt
Error:
sh: 0: Cant' open run.sh
How can I fix it?
-
Aaron over 6 yearsYou might want to use an absolute path or a path relative to the directory from which you run the python program. As it is currently,
sh
is going to look forrun.sh
in its$PATH
, which might differ from your execution context's$PATH
.
-
-
Xantium over 6 yearsAs I thought you need to use the "or"
|
operator run in a shell order.os.system('chmod +x run.sh')
,os.system('./run.sh')
doesn't do it unfortunately because this is equivalent to opening two terminals.