diff --git a/ChangeLog b/ChangeLog index 954bf8db5..8abca9eed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2017-10-01 Bastian Maerkisch + + * src/win/winmain.c|h src/command.c: For wgnuplot, open or attach to a + console when executing system commands so we can its the output. That + in my option eliminates the last benefit of wgnuplot_pipes over + wgnuplot. Note that the process terminates if the new console is + closed, just as is the case with wgnuplot_pipes, but the console is + only opened when actually required. + 2017-09-29 Ethan A Merritt * src/axis.h src/axis.c (axis_set_scale_and_range): Incorrect use diff --git a/src/command.c b/src/command.c index 7564e135a..c0c4f253d 100644 --- a/src/command.c +++ b/src/command.c @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid() { return RCSid("$Id: command.c,v 1.363 2017-09-29 19:38:02 sfeam Exp $"); } +static char *RCSid() { return RCSid("$Id: command.c,v 1.364 2017-10-01 09:01:57 markisch Exp $"); } #endif /* GNUPLOT - command.c */ @@ -124,12 +124,12 @@ int thread_rl_RetCode = -1; /* return code from readline in a thread */ #ifdef _WIN32 # define WIN32_LEAN_AND_MEAN # include -# ifdef __MSC__ +# ifdef _MSC_VER # include # include /* getcwd() */ # else # include -# endif /* !MSC */ +# endif # include # include "win/winmain.h" #endif /* _WIN32 */ @@ -3090,6 +3090,10 @@ do_system(const char *cmd) if (!cmd) return; restrict_popen(); +#if defined(_WIN32) && !defined(WGP_CONSOLE) + /* Open a console so we can see the command's output */ + WinOpenConsole(); +#endif #if defined(_WIN32) && !defined(__WATCOMC__) { LPWSTR wcmd = UnicodeText(cmd, encoding); diff --git a/src/win/winmain.c b/src/win/winmain.c index c837dc0fd..0882cf5e8 100644 --- a/src/win/winmain.c +++ b/src/win/winmain.c @@ -1,5 +1,5 @@ /* - * $Id: winmain.c,v 1.104 2017-09-01 05:21:01 markisch Exp $ + * $Id: winmain.c,v 1.105 2017-10-01 09:01:57 markisch Exp $ */ /* GNUPLOT - win/winmain.c */ @@ -1082,6 +1082,7 @@ fake_pclose(FILE *stream) } #endif + #ifdef WGP_CONSOLE DWORD WINAPI @@ -1465,6 +1466,22 @@ WinMessageLoop(void) } +#ifndef WGP_CONSOLE +void +WinOpenConsole(void) +{ + /* Try to attach to an existing console window. */ + if (AttachConsole(ATTACH_PARENT_PROCESS) == 0) { + if (GetLastError() != ERROR_ACCESS_DENIED) { + /* Open new console if we are are not attached to one already. + Note that closing this console window will end wgnuplot, too. */ + AllocConsole(); + } + } +} +#endif + + void WinRaiseConsole(void) { diff --git a/src/win/winmain.h b/src/win/winmain.h index b4cbf2086..4490c1aee 100644 --- a/src/win/winmain.h +++ b/src/win/winmain.h @@ -1,5 +1,5 @@ /* - * $Id: winmain.h,v 1.20 2016-08-06 13:22:50 markisch Exp $ + * $Id: winmain.h,v 1.21 2017-10-01 09:01:57 markisch Exp $ */ /* GNUPLOT - win/winmain.h */ @@ -71,6 +71,7 @@ void win_sleep(DWORD dwMilliSeconds); TBOOLEAN WinAnyWindowOpen(void); void WinPersistTextClose(void); void WinMessageLoop(void); +void WinOpenConsole(void); void WinRaiseConsole(void); UINT WinGetCodepage(enum set_encoding_id encoding); enum set_encoding_id WinGetEncoding(UINT cp);