I would like to test whether GNUPlot is installed on the system on which my program is running.
For that, I figured I’ll test for the existence of the gnuplot executable in the user’s install locations through stat() call.
However, I don’t know how to read the $PATH environment variable in C so I can test for the existence of the file in those locations.
To read the
PATHenvironment variable, usegetenv("PATH").However, if you just want to run
gnuplotif it’s available, and perform some fallback action if it’s not, then you should just try to run it (e.g. withforkandexecvporposix_spawnp) and handle the failure case.