【发布时间】:2014-12-08 07:56:06
【问题描述】:
我正在使用 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
我哪里错了?请推荐
【问题讨论】:
-
您是否为脚本设置了可执行位?
chmod +x test1.csh?第一行是否有正确的shebang? -
正如我在问题中提到的,它在终端中运行,即 c shell 终端,并且文件是可执行的。
-
@nprak:
subprocess.call()默认情况下不运行任何shell。看到test1.csh顶部的#!/bin/sh了吗?
标签: python linux eclipse shell subprocess