Skip to content

Commit

Permalink
Allow console output from vpnc-script on Windows
Browse files Browse the repository at this point in the history
In commit f3b06b6 ("use CreateProcess instead of system to run scripts.")
we used the CREATE_NO_WINDOW flag to CreateProcess() which avoids creating
a new console window for the vpnc-script, in the GUI client.

That had the side-effect of also not allowing vpnc-script to output to
the *existing* console when invoked from the command-line client. Check
whether there's a console or not and only use CREATE_NO_WINDOW if there
isn't, and both should have the behaviour they desire.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Oct 30, 2014
1 parent 7b8fd00 commit f30e4ae
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions script.c
Expand Up @@ -409,6 +409,7 @@ int script_config_tun(struct openconnect_info *vpninfo, const char *reason)
char *cmd;
PROCESS_INFORMATION pi;
STARTUPINFOW si;
DWORD cpflags;

if (!vpninfo->vpnc_script || vpninfo->script_tun)
return 0;
Expand Down Expand Up @@ -438,8 +439,12 @@ int script_config_tun(struct openconnect_info *vpninfo, const char *reason)

script_env = create_script_env(vpninfo);

if (CreateProcessW(NULL, script_w, NULL, NULL, FALSE,
CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT,
cpflags = CREATE_UNICODE_ENVIRONMENT;
/* If we're running from a console, let the script use it too. */
if (!GetConsoleWindow())
cpflags |= CREATE_NO_WINDOW;

if (CreateProcessW(NULL, script_w, NULL, NULL, FALSE, cpflags,
script_env, NULL, &si, &pi)) {
ret = WaitForSingleObject(pi.hProcess,10000);
CloseHandle(pi.hThread);
Expand Down

0 comments on commit f30e4ae

Please sign in to comment.