Search code examples
makefileterminalautomationscilabheadless

Scilab: tell if we are running headless. Scilab: detect -nw, -nogui


Scilab can really be automated. For instance you can use make to automatically start Scilab that will generate plots and save them to SVG with xs2svg, then start Inkscape to integrate it into a Latex document (with Latex code in legends!).

When using make it is convenient to run Scilab without the main interface by calling it with -nw. If you do not need graphics it can even run without java if called with -nogui.

It would be nice to be able to write scripts that can be either run by a user or by make. With that you could prevent code duplication while allowing easy debugging and report writing. But that means:

  • closing the script when it's done
  • being able to skip some plots that should not be saved
  • etc

So how to detect options -nw or -nogui from within the script?


Solution

  • Using getargs

    function y = nowindows()
        y = (getenv("SCILAB_NW","undefined") ~= "undefined")
    endfunction
    

    then you can use this function:

    if nowindows() then
        mprintf("Running without a window.\n")
        exit()
    end
    

    And if you set the environnement variable SCILAB_NW, nowindows() will return true.

    SCILAB_NW="true" scilab -nw -f yourscript.sce

    This solution adds redundancy to the command used to run Scilab but I found no other way. I also tried to use the sciargs function but I found it less convenient.