alandefreitas / matplotplusplus

Matplot++: A C++ Graphics Library for Data Visualization 📊🗾
https://alandefreitas.github.io/matplotplusplus/
MIT License
4.1k stars 311 forks source link

Quiet mode does not work on windows when matplot is called from a GUI application #376

Closed geral-victor closed 8 months ago

geral-victor commented 8 months ago

Bug category

Describe the bug When creating a figure from a GUI app on windows, in order to generate quietly a plot and save the resulting output as an image, a terminal gets opened.

The problem does not exists if we run the library in a console program.

Steps to Reproduce

{
   auto f = matplot::figure(true); //opens a terminal that is visible, despite having chosen quiet mode.
   ...
   f->save(filename);
}

Dirty fix

{
   auto f = matplot::figure(true); //opens a terminal that is visible, despite having chosen quiet mode.
   ...
   f->save(filename);
   f->backend({}); // dirty patch to close the console opened when matplot++ is called from a GUI, and not a console
}

Platform

Environment Details:

Is seems that the issue is related to the use of _popen : https://github.com/alandefreitas/matplotplusplus/blob/a40344efa9dc5ea0c312e6e9ef4eb7238d98dc12/source/matplot/backend/gnuplot.cpp#L76

It seems that _popen cannot hide windows, as we can read here https://stackoverflow.com/a/10020726/18371648

So we should use CreateProcess instead of _popen