0

サブプロセスモジュールを介して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()

どこが悪いのかわからない。どうすればこれを修正できますか?

4

1 に答える 1

0

これは、python 2および3、linux、およびwindows(gnuplot以外のものを使用)で機能します:

import subprocess
import fcntl
import os
import select


proc = subprocess.Popen(['gnuplot'],
                    stderr=subprocess.PIPE,
                    close_fds=True,
                    universal_newlines=True)
fcntl.fcntl(
    proc.stderr.fileno(),
    fcntl.F_SETFL,
    fcntl.fcntl(proc.stderr.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK)

status = select.select([proc.stderr.fileno()], [], [])[0]
if status:
    out = proc.stderr.read()
print(out)
proc.kill()
于 2014-11-15T14:17:08.237 に答える