0

I'd like to redirect gnuplot error messages (that are normally displayed in the gnuplot terminal) to a file for logging. Is there any way to do this?

Example: if I type

gnuplot> Hi!

in the gnuplot terminal, Then I get

gnuplot> Hi!
         ^
         invalid command
gnuplot> 

Is there any way to redirect "^\ninvalid command" into another file, e.g. err.txt?

Context: I'm using gnuplot embedded in a c++ application using gnuplot-iostream by Dan Stahlke. It works great! But I have no idea how to get error messages from this pipe, so this would be a good work-around.

Ðаn
  • 10,934
  • 11
  • 59
  • 95
aquirdturtle
  • 2,038
  • 26
  • 20
  • Only a vague comment rather than an answer but it may help. I guess `gnuplot` uses `GNU readline` - I may be wrong. Try tagging with `readline` to attract experts in that and maybe try Googling "readline error handling". Sorry, just trying to guess or help with a possible way forward. – Mark Setchell Aug 21 '16 at 11:17

3 Answers3

1

I don't know exactly if this applies on your c++ application (probably not), but I thought I'd mention anyway. If you do:

[user@server]$ gnuplot 2> err.txt
gnuplot> Hi!
gnuplot> exit
[user@server]$ cat err.txt

G N U P L O T
Version 5.0 patchlevel 1    last modified 2015-06-07 

Copyright (C) 1986-1993, 1998, 2004, 2007-2015
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 'aqua'
     ^
     invalid command

Maybe you could incorporate something like this. Hope it helps!

Vinicius Placco
  • 1,683
  • 2
  • 14
  • 24
0

I don't think one can achieve this internally within Gnuplot without tinkering with the source code.

The message "invalid command" is produced in command.c by calling the function int_error (defined in util.c) within which is stderr specified explicitly...

ewcz
  • 12,819
  • 1
  • 25
  • 47
0

It seems gnuplot redirects by default both stdout and stderr to stderr. Instead, terminal file output is send to stdout. Here is an example to check. The content of tmp.gnu.

print 'some text';
set terminal postscript;
set out
pl sin(x)
gnuplot tmp.gnu 2>tmp.txt  1>sin.ps

tmp.txt contains the stdout and sin.ps the postscript file.

Check also this answer https://stackoverflow.com/a/27375957/11769765 to use set print "-", set print "/dev/fd/2" or set print "filename" to redirect stdout.