thooomy
June 8th, 2005, 04:08 AM
Hi there Gurus !
I want to execute perl scripts from within my application an redirect the output into it (and write to their stdin) by using anonymous pipes
If found a part of a sourcecode in the web and modifed it:
static char pBuffer[STD_BUFF_SIZE];
memset(pBuffer,0,STD_BUFF_SIZE);
bool WinNt = false;
STARTUPINFO si;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd; //security information for pipes
PROCESS_INFORMATION pi;
HANDLE newstdin,newstdout,read_stdout,write_stdin; //pipe handles
//check if we're running NT
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize = sizeof(osv);
GetVersionEx(&osv);
WinNt = (osv.dwPlatformId == VER_PLATFORM_WIN32_NT);
if (WinNt) { //initialize security descriptor (Windows NT)
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, true, NULL, false);
sa.lpSecurityDescriptor = &sd;
} else {
sa.lpSecurityDescriptor = NULL;
}
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true; //allow inheritable handles
if (!CreatePipe(&newstdin,&write_stdin,&sa,0)) //create stdin pipe
{
//ErrorMessage("CreatePipe");
//getch();
return("");
}
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) //create stdout pipe
{
//ErrorMessage("CreatePipe");
//getch();
CloseHandle(newstdin);
CloseHandle(write_stdin);
return("");
}
GetStartupInfo(&si); //set startupinfo for the spawned process
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.hStdOutput = newstdout;
si.hStdError = newstdout; //set the new handles for the child process
si.hStdInput = newstdin;
//spawn the child process <<<--- THIS IS THE PROBLEM !
if (!CreateProcess( sExecuteCommandA, NULL, , NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
{
CloseHandle(newstdin);
CloseHandle(newstdout);
CloseHandle(read_stdout);
CloseHandle(write_stdin);
return("");
}
(...)
my Problem is that CreateProcess always fails.
in sExecuteCommandA is a path and a name of a perl script (for example "C:\\Folder\\guestbook.pl"). A valid perl interpreter is runnig on my system...
Is is possible to execute those scripts with this call ?
thank you in advance !
I want to execute perl scripts from within my application an redirect the output into it (and write to their stdin) by using anonymous pipes
If found a part of a sourcecode in the web and modifed it:
static char pBuffer[STD_BUFF_SIZE];
memset(pBuffer,0,STD_BUFF_SIZE);
bool WinNt = false;
STARTUPINFO si;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd; //security information for pipes
PROCESS_INFORMATION pi;
HANDLE newstdin,newstdout,read_stdout,write_stdin; //pipe handles
//check if we're running NT
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize = sizeof(osv);
GetVersionEx(&osv);
WinNt = (osv.dwPlatformId == VER_PLATFORM_WIN32_NT);
if (WinNt) { //initialize security descriptor (Windows NT)
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, true, NULL, false);
sa.lpSecurityDescriptor = &sd;
} else {
sa.lpSecurityDescriptor = NULL;
}
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true; //allow inheritable handles
if (!CreatePipe(&newstdin,&write_stdin,&sa,0)) //create stdin pipe
{
//ErrorMessage("CreatePipe");
//getch();
return("");
}
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) //create stdout pipe
{
//ErrorMessage("CreatePipe");
//getch();
CloseHandle(newstdin);
CloseHandle(write_stdin);
return("");
}
GetStartupInfo(&si); //set startupinfo for the spawned process
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.hStdOutput = newstdout;
si.hStdError = newstdout; //set the new handles for the child process
si.hStdInput = newstdin;
//spawn the child process <<<--- THIS IS THE PROBLEM !
if (!CreateProcess( sExecuteCommandA, NULL, , NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
{
CloseHandle(newstdin);
CloseHandle(newstdout);
CloseHandle(read_stdout);
CloseHandle(write_stdin);
return("");
}
(...)
my Problem is that CreateProcess always fails.
in sExecuteCommandA is a path and a name of a perl script (for example "C:\\Folder\\guestbook.pl"). A valid perl interpreter is runnig on my system...
Is is possible to execute those scripts with this call ?
thank you in advance !