Sometimes I want to use external tools like gnuplot or castle-model-viewer straight from my Ada code. Does anyone know a good way to do that?
If I understand you correctly (and I may not) it’s similar to when I once wanted to use glpk from Ada. In that case I generated a thin binding.
The naive way is to make data files for a gnuplot script or to print out a gnuplot script which the Ada program starts using a procedure “to_os”:
procedure to_os (str : string) is
package c renames interfaces.c;
procedure system_rk (source : in c.char_array);
pragma import (c, system_rk, "system");
begin
system_rk (interfaces.c.to_c (str));
end to_os;
But I would like (at least) to pipe data into a gnuplot script.
This is what I did: https://github.com/pmunts/libsimpleio/blob/f5354ded9aae84452e4b1cb64f3dd52902ac97c2/ada/programs/test_gnuplot.adb
It’s pretty straightforward. External_Command.Pipeline is my wrapper package around popen() and friends. You could also just call popen(), fputs(), and pclose() directly without any wrapper package.
I may ask too impulsively, but where is "“external_command.ads”? I get file “external_command.ads” not found when trying to compile “test_gnuplot.adb”.
I use Util - The Ada 95 Utility Library
The pipe section
can be downloaded from
And the use as pmunts test program, i.e with open/put_line/close
Sorry for the omission. It is part of my Linux Simple I/O Library. If you use Alire, just alr with libsimpleio to pick it up.