W3cubDocs

/Gnuplot

System

Syntax:
system "command string"
! command string
output = system("command string")
show variable GPVAL_SYSTEM

system "command" executes "command" in a subprocess by invoking the operating system's default shell. If called as a function, system("command") returns the character stream from the subprocess's stdout as a string. One trailing newline is stripped from the resulting string if present. See also backquotes.

The exit status of the subprocess is reported in variables GPVAL_SYSTEM_ERRNO and GPVAL_SYSTEM_ERRMSG. Note that if the command string invokes more than one programs, the subprocess may return "Success" even if one of the programs produced an error. E.g. file = system("ls -1 *.plt | tail -1") will return "Success" even if there are no *.plt files because tail succeeds even if ls does not.

The system command can be used to import external functions into gnuplot as shown below, however this will force creation of a separate subprocess every time the function is invoked. For functions that will be invoked many times it would be better to import a directly callable subroutine from a shared library. See import and plugin.dem.

f(x) = real(system(sprintf("somecommand %f", x)))

Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
Distributed under the gnuplot license (rights to distribute modified versions are withheld).