简体   繁体   中英

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. I want to run a simple c shell script through Python using subprocess as follows:

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

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:

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. As Lukas Graf commented, also check the shebang ( #!... ) in the first line.

To confirm that, before run it through Python, run it in the shell.

$ 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. Or change the working directory configuration in the PyDev.

UPDATE

Prepend the shell executable:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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