Skip to content

Commit

Permalink
Open or attach to a console when executing system commands
Browse files Browse the repository at this point in the history
  • Loading branch information
markisch committed Oct 1, 2017
1 parent e1768ba commit 2c30a03
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2017-10-01 Bastian Maerkisch <[email protected]>

* 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 <[email protected]>

* src/axis.h src/axis.c (axis_set_scale_and_range): Incorrect use
Expand Down
10 changes: 7 additions & 3 deletions src/command.c
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -124,12 +124,12 @@ int thread_rl_RetCode = -1; /* return code from readline in a thread */
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# ifdef __MSC__
# ifdef _MSC_VER
# include <malloc.h>
# include <direct.h> /* getcwd() */
# else
# include <alloc.h>
# endif /* !MSC */
# endif
# include <htmlhelp.h>
# include "win/winmain.h"
#endif /* _WIN32 */
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion src/win/winmain.c
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -1082,6 +1082,7 @@ fake_pclose(FILE *stream)
}
#endif


#ifdef WGP_CONSOLE

DWORD WINAPI
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion src/win/winmain.h
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2c30a03

Please sign in to comment.