Commit 44a4c6bd authored by Brad King's avatar Brad King

ENH: Implemented SetWorkingDirectory method.

parent 54fb465a
......@@ -99,10 +99,11 @@ kwsysEXPORT void kwsysProcess_SetCommand(kwsysProcess* cp,
kwsysEXPORT void kwsysProcess_SetTimeout(kwsysProcess* cp, double timeout);
/**
* Set the working directory for the child process. The working directory can
* be absolute or relative to the current directory.
* Set the working directory for the child process. The working
* directory can be absolute or relative to the current directory.
*/
kwsysEXPORT void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir);
kwsysEXPORT void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp,
const char* dir);
/**
* Get the current state of the Process instance. Possible states are:
......
......@@ -167,6 +167,7 @@ void kwsysProcess_Delete(kwsysProcess* cp)
/* Free memory. */
kwsysProcess_SetCommand(cp, 0);
kwsysProcess_SetWorkingDirectory(cp, 0);
free(cp);
}
......@@ -227,7 +228,7 @@ void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir)
}
if(dir)
{
cp->WorkingDirectory = (char*) malloc(strlen(dir) + 1);
cp->WorkingDirectory = (char*)malloc(strlen(dir) + 1);
strcpy(cp->WorkingDirectory, dir);
}
}
......@@ -345,6 +346,20 @@ void kwsysProcess_Execute(kwsysProcess* cp)
/* Restore all default signal handlers. */
kwsysProcessRestoreDefaultSignalHandlers();
/* Change to the working directory specified, if any. */
if(cp->WorkingDirectory)
{
/* Some platforms specify that the chdir call may be
interrupted. Repeat the call until it finishes. */
int r;
while(((r = chdir(cp->WorkingDirectory)) < 0) && (errno == EINTR));
if(r < 0)
{
/* Failure. Report error to parent and terminate. */
kwsysProcessChildErrorExit(cp);
}
}
/* Execute the real process. If successful, this does not return. */
execvp(cp->Command[0], cp->Command);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment