我正在尝试通过子进程模块读取和打印 gnuplot 的初始屏幕:
G N U P L O T
Version 4.6 patchlevel 4 last modified 2013-10-02
Build System: Linux x86_64
Copyright (C) 1986-1993, 1998, 2004, 2007-2013
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
faq, bugs, etc: type "help FAQ"
immediate help: type "help" (plot window: hit 'h')
Terminal type set to 'wxt'
这是我的代码:
from subprocess
import PIPE, Popen
import fcntl, os
class Gnuplot:
def __init__(self, debug=True):
self.debug = debug
if self.debug:
print 'Initializing ...\n'
# start process
self.proc = subprocess.Popen(['gnuplot'],stdin=PIPE,stdout=PIPE,stderr=PIPE)
# set stderr as nonblocking so that we can skip when there is nothing
fcntl.fcntl(self.proc.stderr.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
#a = self.proc.communicate()
fcntl.fcntl(self.proc.stderr.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
cout = self.proc.communicate()
if self.debug:
print 'Done!\n'
print cout
g= Gnuplot()
我不知道我的错在哪里。我怎样才能解决这个问题?