|
From: Ethan M. <merritt@u.washington.edu> - 2006-03-08 22:44:23
|
On Wednesday 08 March 2006 01:26 pm, Petr Mikulik wrote:
> >> pipeexist(s) which returns 1 for "-" and 1/0 whether it is a
> >> pipe wherefrom you can read at least 1 byte;
> >
> > Huh? But that is quite broken. If you read from that data source,
> > even 1 byte, then you have poisoned it for actual plotting.
>
> I don't think so. plot '<awk {blalbal} bla.dat' gives always the
> same. Can you give an counter-example?
Any real-time data source?
A keyboard input stream?
A pipe to another interactive program?
> >> The truth is that popen() "never" returns NULL
> >> (contrary to specification) -- at least for OS/2, Windows, Linux.
> >
> > On linux it returns NULL if the pipe open fails.
>
> No, it does NOT! Try it!
> popen("bla bla", "r") does not return NULL
It does not return NULL in that case because it successfully opened
a pipe to the forked command "/bin/sh bla bla". The forked shell
itself returned an error ("command not found").
But there is no pipe failure here.
> I would prefer no system error message at all.
Then you must configure your shell environment to not
print an error. This is being printed by /bin/sh, not by gnuplot.
The fact that it is printed at all is an indication that the popen()
did in fact succeed.
> But popen() did not return NULL. So I must read at least one byte.
You are looking in the wrong place for the error return.
If you want to do error checking, you need something like this:
--- gnuplot/src/datafile.c 2006-01-27 08:36:48.000000000 -0800
+++ gnuplot-cvs/src/datafile.c 2006-03-08 14:25:53.000000000 -0800
@@ -1343,7 +1343,9 @@
if (!mixed_data_fp) {
#if defined(PIPES)
if (df_pipe_open) {
- (void) pclose(data_fp);
+ int ierr = pclose(data_fp);
+ if (ierr)
+ fprintf(stderr,"pipe error %s\n",strerror(ierr));
df_pipe_open = FALSE;
} else
#endif /* PIPES */
With that patch in place, your test example gives:
gnuplot> plot "< bla bla"
sh: bla: command not found
pipe error Unknown error 32512
I'm not sure how to make it print a more interpretable error message
string, but I assume that 32512 in fact means "command not found".
> > Anyhow, my main point is that an xxx_exists() routine should be
> > exactly parallel to the routine used for actual data input.
> > Otherwise you cannot trust the result as an indication of whether
> > you will or will not be able to plot it. Thus it should handle
> > both files and pipes, because the data input routine handles both
> > files and pipes.
>
> Then I propose streamexist() that would do all of that; it would
> be equivalent to
> if (fileexist(file_in_path(x)) || pipeexist(x))
OK, but the pipe part of the test must not actually read any data.
--
Ethan A Merritt
Biomolecular Structure Center
University of Washington, Seattle WA
|