简体   繁体   English

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

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

I am using Centos 7.0 and have installed Eclipse Kepler in the Pydev environment. 我正在使用Centos 7.0,并已在Pydev环境中安装了Eclipse Kepler。 I want to run a simple c shell script through Python using subprocess as follows: 我想使用以下子进程通过Python运行一个简单的c shell脚本:

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

This c shell script executes in the terminal and also if I run command like "ls" or ""pwd then I get the correct output eg 这个C Shell脚本在终端中执行,而且如果我运行“ ls”或“ pwd”之类的命令,则可以获得正确的输出,例如

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

But when I run subprocess.call(["./test1.csh"]), I get the following error: 但是,当我运行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

Where am I going wrong? 我要去哪里错了? Please suggest 请建议

Make sure that the file test1.csh is executable. 确保文件test1.csh是可执行文件。 As Lukas Graf commented, also check the shebang ( #!... ) in the first line. 正如Lukas Graf所评论的那样,还要检查第一行中的shebang( #!... )。

To confirm that, before run it through Python, run it in the shell. 为了确认这一点,在通过Python运行之前,请在外壳中运行它。

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

The current working directory will be different from when you run it in the terminal. 当前的工作目录将与您在终端中运行时的目录不同。 Specify the full path of the shell script. 指定shell脚本的完整路径。 Or change the working directory configuration in the PyDev. 或在PyDev中更改工作目录配置。

UPDATE UPDATE

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

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

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

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