无法从 python 子进程执行 shell 脚本:权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20291543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't execute shell script from python subprocess: permission denied
提问by Quanquan Liu
Tried googling but couldn't find something that relates to my particular problem. I'm trying to run a shell script from python but the shell script wouldn't run because of a permission denied error. The python code I'm running is:
尝试使用谷歌搜索但找不到与我的特定问题相关的内容。我正在尝试从 python 运行 shell 脚本,但由于权限被拒绝错误,shell 脚本无法运行。我正在运行的python代码是:
process = subprocess.Popen('run.sh', shell=True, stdout=subprocess.PIPE)
process.wait()
....
os.killpg(pro.pid, signal.SIGTERM)
The error I'm getting:
我得到的错误:
python RunScript.py "input"
/bin/sh: 1: run.sh: Permission denied
The contents of my shell script is:
我的shell脚本的内容是:
#!/bin/sh
abspath=$(cd "$(dirname "chmod +x run.sh
")"; pwd)
CLASSPATH=$CLASSPATH:$abspath/"lib/*":$abspath/"bin"
export CLASSPATH
java -classpath $CLASSPATH my.folder.path.Class $abspath/../data/data.txt $abspath/../data/data2.txt
Thanks in advance.
提前致谢。
采纳答案by PasteBT
Check your run.sh mode, if no executable flag, set it with command
检查您的 run.sh 模式,如果没有可执行标志,请使用命令进行设置
##代码##回答by Arovit
its because you don't have permission to run that script. You will need to give executable permission for that script to run.
这是因为您无权运行该脚本。您需要授予该脚本的可执行权限才能运行。
chmod a+x run.sh
chmod a+x 运行.sh

