拒绝通过SubProcess.call运行Shell脚本的权限
我使用python编写了一个shell脚本,它通过命令bash download_r1.sh
在我的终端上成功运行。
我想测试子过程是否可以在Python中执行相同的操作,因为我想将管道集成在Python脚本中。这是我代码的子过程部分:
downR1 = subprocess.call('./download_R1.sh')
它未能运行以下错误消息来运行脚本:
Error message:
PermissionError: [Errno 13] Permission denied: './download_R1.sh'
有人建议使用chmod +x
获得该脚本的授权。但是bash down.sh
正在工作。我不知道哪一部分出错。
有建议吗?
I wrote a shell script using python and it successfully run by command bash download_R1.sh
on my terminal.
I wanted to test if subprocess can do the same thing in python because I would like to integrate a pipeline in python script. Here is the subprocess part of my code:
downR1 = subprocess.call('./download_R1.sh')
It failed to run the script with following error message:
Error message:
PermissionError: [Errno 13] Permission denied: './download_R1.sh'
Someone suggested using chmod +x
to obtain authenitification of that script. But bash down.sh
is working. I don't know which part goes wrong.
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是外壳行为的正常方式。
如果没有执行特权(
+X
),则 无法直接运行程序或脚本或任何运行文件的内容,即使没有
+x
foo.sh
foo.py.py
在您的情况下,如果您想运行程序使用
subprocess
,但不给您必须使用的文件执行特权:如果您需要将参数传递给脚本,只需将更多项目添加到列表中:
有关使用子程序的一些问题=“ https://stackoverflow.com/questions/11679936/python-subprocess-arguments”>喜欢这个。
如果您喜欢写入命令,请仅建议使用
shell = true
是不推荐。但是您可以使用类似的东西:That's the normal way the shell behaves.
You can not directly run a program or script if it not has execution privileges (
+x
)But, you can instruct other program
bash
,python
or whatever to run a file even if not has+x
foo.sh
foo.py
In your case, if you want to run the program with
subprocess
but not giving execution privileges to the file you must use:If you need to pass arguments to the script just add more items to the list:
There are several questions about using subprocess an arguments like this one.
If you prefer write you command in only one string be advised that use
shell=True
is not recommended. But you can use something like: