ENH: Added show/hide window support.
This commit is contained in:
parent
27289e3267
commit
59d886d0f4
|
@ -54,6 +54,9 @@ int main()
|
||||||
This is parsed off the command line. */
|
This is parsed off the command line. */
|
||||||
HANDLE killEvent = 0;
|
HANDLE killEvent = 0;
|
||||||
|
|
||||||
|
/* Flag for whether to hide window of child process. */
|
||||||
|
int hideWindow = 0;
|
||||||
|
|
||||||
/* An array of the handles on which we wait when the child is
|
/* An array of the handles on which we wait when the child is
|
||||||
running. */
|
running. */
|
||||||
HANDLE waitHandles[2] = {0, 0};
|
HANDLE waitHandles[2] = {0, 0};
|
||||||
|
@ -79,6 +82,11 @@ int main()
|
||||||
while(*cmdLine && *cmdLine == ' ') { ++cmdLine; }
|
while(*cmdLine && *cmdLine == ' ') { ++cmdLine; }
|
||||||
sscanf(cmdLine, "%p", &killEvent);
|
sscanf(cmdLine, "%p", &killEvent);
|
||||||
|
|
||||||
|
/* Parse the hide window flag. */
|
||||||
|
while(*cmdLine && *cmdLine != ' ') { ++cmdLine; }
|
||||||
|
while(*cmdLine && *cmdLine == ' ') { ++cmdLine; }
|
||||||
|
sscanf(cmdLine, "%d", &hideWindow);
|
||||||
|
|
||||||
/* Skip to the beginning of the command line of the real child. */
|
/* Skip to the beginning of the command line of the real child. */
|
||||||
while(*cmdLine && *cmdLine != ' ') { ++cmdLine; }
|
while(*cmdLine && *cmdLine != ' ') { ++cmdLine; }
|
||||||
while(*cmdLine && *cmdLine == ' ') { ++cmdLine; }
|
while(*cmdLine && *cmdLine == ' ') { ++cmdLine; }
|
||||||
|
@ -88,7 +96,7 @@ int main()
|
||||||
ZeroMemory(&pi, sizeof(pi));
|
ZeroMemory(&pi, sizeof(pi));
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||||
si.wShowWindow = SW_SHOWDEFAULT;
|
si.wShowWindow = hideWindow?SW_HIDE:SW_SHOWDEFAULT;
|
||||||
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
|
|
@ -140,6 +140,9 @@ struct kwsysProcess_s
|
||||||
/* The working directory for the child process. */
|
/* The working directory for the child process. */
|
||||||
char* WorkingDirectory;
|
char* WorkingDirectory;
|
||||||
|
|
||||||
|
/* Whether to hide the child process's window. */
|
||||||
|
int HideWindow;
|
||||||
|
|
||||||
/* On Win9x platforms, the path to the forwarding executable. */
|
/* On Win9x platforms, the path to the forwarding executable. */
|
||||||
char* Win9x;
|
char* Win9x;
|
||||||
|
|
||||||
|
@ -638,17 +641,21 @@ void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir)
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
int kwsysProcess_GetOption(kwsysProcess* cp, int optionId)
|
int kwsysProcess_GetOption(kwsysProcess* cp, int optionId)
|
||||||
{
|
{
|
||||||
(void)cp;
|
switch(optionId)
|
||||||
(void)optionId;
|
{
|
||||||
return 0;
|
case kwsysProcess_Option_HideWindow: return cp->HideWindow;
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void kwsysProcess_SetOption(kwsysProcess* cp, int optionId, int value)
|
void kwsysProcess_SetOption(kwsysProcess* cp, int optionId, int value)
|
||||||
{
|
{
|
||||||
(void)cp;
|
switch(optionId)
|
||||||
(void)optionId;
|
{
|
||||||
(void)value;
|
case kwsysProcess_Option_HideWindow: cp->HideWindow = value; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
@ -692,6 +699,7 @@ void kwsysProcess_Execute(kwsysProcess* cp)
|
||||||
|
|
||||||
/* Windows child startup control data. */
|
/* Windows child startup control data. */
|
||||||
STARTUPINFO si;
|
STARTUPINFO si;
|
||||||
|
DWORD dwCreationFlags=0;
|
||||||
|
|
||||||
/* Do not execute a second time. */
|
/* Do not execute a second time. */
|
||||||
if(cp->State == kwsysProcess_State_Executing)
|
if(cp->State == kwsysProcess_State_Executing)
|
||||||
|
@ -761,9 +769,9 @@ void kwsysProcess_Execute(kwsysProcess* cp)
|
||||||
/* The forwarding executable is given a handle to the error pipe
|
/* The forwarding executable is given a handle to the error pipe
|
||||||
and a handle to the kill event. */
|
and a handle to the kill event. */
|
||||||
cp->RealCommand = malloc(strlen(cp->Win9x)+strlen(cp->Command)+100);
|
cp->RealCommand = malloc(strlen(cp->Win9x)+strlen(cp->Command)+100);
|
||||||
sprintf(cp->RealCommand, "%s %p %p %s", cp->Win9x,
|
sprintf(cp->RealCommand, "%s %p %p %d %s", cp->Win9x,
|
||||||
cp->Pipe[CMPE_PIPE_ERROR].Write,
|
cp->Pipe[CMPE_PIPE_ERROR].Write, cp->Win9xKillEvent,
|
||||||
cp->Win9xKillEvent, cp->Command);
|
cp->HideWindow, cp->Command);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -776,24 +784,16 @@ void kwsysProcess_Execute(kwsysProcess* cp)
|
||||||
si.hStdOutput = cp->Pipe[CMPE_PIPE_STDOUT].Write;
|
si.hStdOutput = cp->Pipe[CMPE_PIPE_STDOUT].Write;
|
||||||
si.hStdError = cp->Pipe[CMPE_PIPE_STDERR].Write;
|
si.hStdError = cp->Pipe[CMPE_PIPE_STDERR].Write;
|
||||||
|
|
||||||
/* Hide the forwarding executable console on Windows 9x. */
|
/* Decide whether a child window should be shown. */
|
||||||
si.dwFlags |= STARTF_USESHOWWINDOW;
|
si.dwFlags |= STARTF_USESHOWWINDOW;
|
||||||
if(cp->Win9x)
|
si.wShowWindow = cp->HideWindow?SW_HIDE:SW_SHOWDEFAULT;
|
||||||
{
|
|
||||||
si.wShowWindow = SW_HIDE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
si.wShowWindow = SW_SHOWDEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The timeout period starts now. */
|
/* The timeout period starts now. */
|
||||||
cp->StartTime = kwsysProcessTimeGetCurrent();
|
cp->StartTime = kwsysProcessTimeGetCurrent();
|
||||||
cp->TimeoutTime = kwsysProcessTimeFromDouble(-1);
|
cp->TimeoutTime = kwsysProcessTimeFromDouble(-1);
|
||||||
|
|
||||||
/* CREATE THE CHILD PROCESS */
|
/* CREATE THE CHILD PROCESS */
|
||||||
if(!CreateProcess(0, cp->RealCommand, 0, 0, TRUE,
|
if(!CreateProcess(0, cp->RealCommand, 0, 0, TRUE, dwCreationFlags, 0,
|
||||||
cp->Win9x? CREATE_NEW_CONSOLE:DETACHED_PROCESS, 0,
|
|
||||||
cp->WorkingDirectory, &si, &cp->ProcessInformation))
|
cp->WorkingDirectory, &si, &cp->ProcessInformation))
|
||||||
{
|
{
|
||||||
kwsysProcessCleanup(cp, 1);
|
kwsysProcessCleanup(cp, 1);
|
||||||
|
|
Loading…
Reference in New Issue