Command-line mode does not print script messages - Easy to fix?
Submitted by Mike
Link to original bug (#676315)
Description
Dear all,
Using script-fu from the command line does not print the script messages on the console window that opens. This is quite annoying for long-running, multi-file scripts.
I've read in several forums that the problem is that the Windows application is not built as a console application, and therefore it doesn't have a binding for stdout.
If this is the case, it should be pretty straight-forward to solve it. Using AllocConsole() with freopen() should solve the problem, if it is as trivial as it seems.
The gimp could execute these sentences in a separate function when it is built for Windows and ran in non-interactive, batch-mode. It could even be selected through a command-line switch, so not to break other functionality.
The code could look something similar to this:
bool CreateTextConsole() { if (!AllocConsole()) return false;
// Set-up stdout to point to the console buffer
if (freopen("CONOUT$", "wt", stdout) == NULL)
return false;
// Set-up stdin
if (freopen("CONIN$", "rt", stdin) == NULL)
return false;
// Optional - Add a signal controller to capture CTRL+C, etc.
if ( ! SetConsoleCtrlHandler(TextConsoleHandler, TRUE) )
return false;
printf("Console system correctly initialized...\n");
return true;
}
Version: 2.8.0