summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/ProcessWin32.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2003-12-16 22:20:01 (GMT)
committerBrad King <brad.king@kitware.com>2003-12-16 22:20:01 (GMT)
commit802601b6067198e175b34cb7a5133f5b491b4f2f (patch)
treef952856bbb5a759444c5147ea9634673faf4f06f /Source/kwsys/ProcessWin32.c
parentab0a30e2b3f2fc3fc8d3eacddd7f7e2210faa426 (diff)
downloadCMake-802601b6067198e175b34cb7a5133f5b491b4f2f.zip
CMake-802601b6067198e175b34cb7a5133f5b491b4f2f.tar.gz
CMake-802601b6067198e175b34cb7a5133f5b491b4f2f.tar.bz2
ENH: Added SetPipeShared method to allow stdout and stderr pipes to be shared with the parent process.
Diffstat (limited to 'Source/kwsys/ProcessWin32.c')
-rw-r--r--Source/kwsys/ProcessWin32.c81
1 files changed, 75 insertions, 6 deletions
diff --git a/Source/kwsys/ProcessWin32.c b/Source/kwsys/ProcessWin32.c
index d1d3c5e..c710fac 100644
--- a/Source/kwsys/ProcessWin32.c
+++ b/Source/kwsys/ProcessWin32.c
@@ -184,6 +184,11 @@ struct kwsysProcess_s
char* PipeFileSTDOUT;
char* PipeFileSTDERR;
+ /* Whether each pipe is shared with the parent process. */
+ int PipeSharedSTDIN;
+ int PipeSharedSTDOUT;
+ int PipeSharedSTDERR;
+
/* Handle to automatically delete the Win9x forwarding executable. */
HANDLE Win9xHandle;
@@ -264,6 +269,9 @@ kwsysProcess* kwsysProcess_New()
}
ZeroMemory(cp, sizeof(*cp));
+ /* Share stdin with the parent process by default. */
+ cp->PipeSharedSTDIN = 1;
+
/* Set initial status. */
cp->State = kwsysProcess_State_Starting;
@@ -805,10 +813,40 @@ int kwsysProcess_SetPipeFile(kwsysProcess* cp, int pipe, const char* file)
}
strcpy(*pfile, file);
}
+
+ /* If we are redirecting the pipe, do not share it. */
+ if(*pfile)
+ {
+ kwsysProcess_SetPipeShared(cp, pipe, 0);
+ }
+
return 1;
}
/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetPipeShared(kwsysProcess* cp, int pipe, int shared)
+{
+ if(!cp)
+ {
+ return;
+ }
+
+ switch(pipe)
+ {
+ case kwsysProcess_Pipe_STDIN: cp->PipeSharedSTDIN = shared?1:0; break;
+ case kwsysProcess_Pipe_STDOUT: cp->PipeSharedSTDOUT = shared?1:0; break;
+ case kwsysProcess_Pipe_STDERR: cp->PipeSharedSTDERR = shared?1:0; break;
+ default: return;
+ }
+
+ /* If we are sharing the pipe, do not redirect it to a file. */
+ if(shared)
+ {
+ kwsysProcess_SetPipeFile(cp, pipe, 0);
+ }
+}
+
+/*--------------------------------------------------------------------------*/
int kwsysProcess_GetOption(kwsysProcess* cp, int optionId)
{
if(!cp)
@@ -973,6 +1011,15 @@ void kwsysProcess_Execute(kwsysProcess* cp)
}
}
+ /* Replace the stderr pipe with the parent process's if requested.
+ In this case the pipe thread will still run but never report
+ data. */
+ if(cp->PipeSharedSTDERR)
+ {
+ kwsysProcessCleanupHandle(&si.StartupInfo.hStdError);
+ si.StartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
+ }
+
/* Create the pipeline of processes. */
{
HANDLE readEnd = 0;
@@ -989,12 +1036,18 @@ void kwsysProcess_Execute(kwsysProcess* cp)
/* Release resources that may have been allocated for this
process before an error occurred. */
kwsysProcessCleanupHandle(&readEnd);
- if(i > 0)
+ if(si.StartupInfo.hStdInput != GetStdHandle(STD_INPUT_HANDLE))
{
kwsysProcessCleanupHandle(&si.StartupInfo.hStdInput);
}
- kwsysProcessCleanupHandle(&si.StartupInfo.hStdOutput);
- kwsysProcessCleanupHandle(&si.StartupInfo.hStdError);
+ if(si.StartupInfo.hStdOutput != GetStdHandle(STD_OUTPUT_HANDLE))
+ {
+ kwsysProcessCleanupHandle(&si.StartupInfo.hStdOutput);
+ }
+ if(si.StartupInfo.hStdOutput != GetStdHandle(STD_ERROR_HANDLE))
+ {
+ kwsysProcessCleanupHandle(&si.StartupInfo.hStdError);
+ }
kwsysProcessCleanupHandle(&si.ErrorPipeRead);
kwsysProcessCleanupHandle(&si.ErrorPipeWrite);
return;
@@ -1533,10 +1586,14 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
}
si->StartupInfo.hStdInput = fin;
}
- else
+ else if(cp->PipeSharedSTDIN)
{
si->StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
}
+ else
+ {
+ si->StartupInfo.hStdInput = INVALID_HANDLE_VALUE;
+ }
/* Setup the process's stdout. */
{
@@ -1578,6 +1635,15 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
}
}
+ /* Replace the stdout pipe with the parent process's if requested.
+ In this case the pipe thread will still run but never report
+ data. */
+ if(index == cp->NumberOfCommands-1 && cp->PipeSharedSTDOUT)
+ {
+ kwsysProcessCleanupHandle(&si->StartupInfo.hStdOutput);
+ si->StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
+ }
+
/* Create the child process. */
{
BOOL r;
@@ -1678,8 +1744,11 @@ int kwsysProcessCreate(kwsysProcess* cp, int index,
kwsysProcessCleanupHandle(&si->StartupInfo.hStdInput);
}
- /* The parent process does not need the inhertied pipe write end. */
- kwsysProcessCleanupHandle(&si->StartupInfo.hStdOutput);
+ if(si->StartupInfo.hStdOutput != GetStdHandle(STD_OUTPUT_HANDLE))
+ {
+ /* The parent process does not need the inhertied pipe write end. */
+ kwsysProcessCleanupHandle(&si->StartupInfo.hStdOutput);
+ }
return 1;
}