无法从Eclips中的Pydev环境运行shell脚本

2024-05-13 23:55:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是centos7.0,并在Pydev环境中安装了Eclipse开普勒。我想使用下面的子进程通过Python运行一个简单的c shell脚本:

import subprocess
subprocess.call(["./test1.csh"])

这个c shell脚本在终端中执行,如果我运行“ls”或“pwd”之类的命令,那么我会得到正确的输出,例如

^{pr2}$

但当我跑的时候subprocess.call([“/test1.csh”]),我得到以下错误:

Traceback (most recent call last):
File "/home/nishant/workspace/codec_implement/src/NTTool/raw2waveconvert.py", line 8, in <module>
    subprocess.call(["./test1.csh"])
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 1308, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied

我哪里出错了?请提出建议


Tags: inpy脚本child环境usrlineshell
1条回答
网友
1楼 · 发布于 2024-05-13 23:55:33

确保文件test1.csh是可执行的。正如lukasgraf评论的那样,还要检查第一行中的shebang(#!...)。在

要确认这一点,在通过Python运行它之前,请在shell中运行它。在

$ ls -l test1.csh
...
$ ./test1.csh

当前工作目录将与在终端中运行时不同。指定shell脚本的完整路径。或者更改PyDev中的工作目录配置。在

更新

预先准备shell可执行文件:

^{pr2}$

相关问题 更多 >