I'm writing a simple binding to gnuplot in Lua. In Lua, I can execute commands in system shell with execute
and pipe data to gnuplot with popen
which behave pretty much like in C language. The problem with the latter function is that I can either read from that pipe or write to it. I can open this pipe in 'write' mode and write an entire script line by line, but I will not be able to read from gnuplot stdout which I would like to do. The reason I want to do it is that I can read, for example, an entire png picture as a byte array and pass it to another module to be displayed. I would like to use only pipes and avoid creating temporary files.
I know that I can pass commands through command line to gnuplot with -e
flag, but it seems I can't put datablocks in here. I'm looking for a way to somehow pipe an entire script to gnuplot, both commands and datablocks. Just like I would execute it from a file.
I'm doing all this on Windows 10 with cmd shell and I'd like to stick to utilities that are available in my OS so my script remains portable, but I have access to ported GNU coreutils and GNU shell.
Upd. echo plot x | gnuplot
allows me to pipe commands to gnuplot. But I can't figure out how to pipe a datablock. A datablock is created like this:
$Mydata << EOD
11 22 33
44 55 66
77 88 99
EOD
Rows must be separated with a new line, but it seems I cannot print new line symbol with echo
command.
Thanks to a tip from Mark Setchell, I found a way to build the script in the command line and pipe it to gnuplot splitting lines with &echo
:
(echo set monochrome&echo $DATA ^^^<^^^<EOD&echo 1&echo 3&echo 9&echo EOD&echo plot $DATA) | gnuplot
This command plots values 1, 3, 9 in gnuplot with monochrome palette.
Unfortunately, maximum length of a single command is limited, therefore, this method is not applicable for large amounts of data.