繁体   English   中英

无法在Eclipse中的Pydev环境中运行Shell脚本

[英]Unable to run shell script from the Pydev environment in Eclipse

我正在使用Centos 7.0,并已在Pydev环境中安装了Eclipse Kepler。 我想使用以下子进程通过Python运行一个简单的c shell脚本:

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

这个C Shell脚本在终端中执行,而且如果我运行“ ls”或“ pwd”之类的命令,则可以获得正确的输出,例如

subprocess.call(["ls"]) # give me the list of all files
subprocess.call(["pwd"]) # gives me the location of current directory.

但是,当我运行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

我要去哪里错了? 请建议

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

为了确认这一点,在通过Python运行之前,请在外壳中运行它。

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

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

UPDATE

在shell可执行文件之前添加:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM