Connecting to gnuplot with Popen?

A

Anton81

Hi,

it seems to be a FAQ, but I still haven't found a solution. I want to
control gnuplot with a python program. The following at least gives me the
gnuplot output:

subp=Popen("gnuplot",stdin=None,stderr=PIPE,stdout=PIPE)
....
subp.stderr.readline()

even though I'm not sure how to check if no more lines can be read with
readline() so that it doesn't block.
But after the script has finished, the console doesn't show me the
characters I type.

However, as soon as I try:

subp=Popen("gnuplot",stdin=PIPE,stderr=PIPE,stdout=PIPE)
....
subp.stderr.readline()

the program hangs.

What's wrong?

Anton
 
M

Markus Weihs

I want to control gnuplot with a python program.

Hi Anton,

here is a little snippet using os.popen:


import os

gp = os.popen('gnuplot -persist', 'w')
print >> gp, "set yrange [-300:300]"
for n in range(300):
print >> gp, "plot %i*cos(x)+%i*log(x+10)" % (n,150-n)


Regards, mawe
 
A

Anton81

Hi Anton,
here is a little snippet using os.popen:

Unfortunately I'm having more problem getting the output from Gnuplot, which
I'd like to examine for error messages and settings of options.

Anton
 
J

John J. Lee

Anton81 said:
Unfortunately I'm having more problem getting the output from Gnuplot, which
I'd like to examine for error messages and settings of options.

If you must roll your own, look at standard module subprocess.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top