Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python对popen.communicate的调用不提供任何输出_Python - Fatal编程技术网

python对popen.communicate的调用不提供任何输出

python对popen.communicate的调用不提供任何输出,python,Python,我有一个类函数声明为 def catFunc(self,filename): print "catFunc",filename process = subprocess.Popen(['cat',/root/scratch.php], stdout=subprocess.PIPE, shell=True) out, err = process.communicate() print (out) print (err) 就这样叫 fn = '/ro

我有一个类函数声明为

    def catFunc(self,filename):
    print "catFunc",filename
    process = subprocess.Popen(['cat',/root/scratch.php], stdout=subprocess.PIPE, shell=True)
    out, err = process.communicate()
    print (out)
    print (err)
就这样叫

fn = '/root/scratch.php'
self.catFunc(fn)
但我看不到任何结果,也不知道为什么


非常感谢您对阅读文件内容的任何帮助

def catFunc(self,filename):
    with open(filename) as f:
        s = f.read()
    return s
如果需要使用子流程模块:

import subprocess

def catFunc(filename):
    print "catFunc"
    task = subprocess.Popen(["cat", filename], stdout=subprocess.PIPE)
    print list(task.stdout)

catFunc()

读取文件内容的步骤

def catFunc(self,filename):
    with open(filename) as f:
        s = f.read()
    return s
如果需要使用子流程模块:

import subprocess

def catFunc(filename):
    print "catFunc"
    task = subprocess.Popen(["cat", filename], stdout=subprocess.PIPE)
    print list(task.stdout)

catFunc()

要检索shell命令的输出,建议使用
子进程。与
shlex.split
合作检查\u output

例如:

output = subprocess.check_output(shlex.split('cat "root/scratch.php"')

也就是说,根据当前的问题标题,Rakesh是正确的。

要检索shell命令的输出,建议使用
子进程。与
shlex.split
合作检查输出

例如:

output = subprocess.check_output(shlex.split('cat "root/scratch.php"')

也就是说,根据当前的问题标题,Rakesh是正确的。

我知道我可以打点它-我的目的是解除popen.Communication功能我知道我可以打点它-我的目的是解除popen.Communication功能可能流程没有?或者更好的方法是通过打印其
进程来检查Popen是否失败。returncode
。返回代码为none可能进程没有?或者最好通过打印其
进程来检查Popen是否失败。returncode
。返回代码为None