我试图通过python运行gnuplot。在
我可以发送和运行命令,但不能从应用程序读取警告或错误消息。它就在这里等着:“自我过程标准输出.readline()”。在
以下是我的全部代码:from subprocess import PIPE, Popen
import fcntl, os
class Gnuplot:
def __init__(self, debug=True):
self.debug = debug
if self.debug:
print 'Initializing ...\n'
self.proc = Popen(['gnuplot','-persist'],stdin=PIPE, stdout=PIPE, stderr=PIPE)
fcntl.fcntl(self.proc.stderr.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
def communicate(self, cin='\n'):
self.proc.stdin.write(cin+'\n')
cout, cerr = '', ''
print "lol"
if self.proc.stdout:
cout = self.proc.stdout.readline()
self.proc.stdout.close()
print cout
elif self.proc.stderr:
cerr = self.proc.stderr.read()
self.proc.stderr.close()
print cerr
if __name__ == '__main__':
g = Gnuplot()
g.communicate("set parameter\n")
g.communicate("plot sin(x)\n")
它就在这里等着:
^{pr2}$