Yeah, now are working all the methods!!! Thank's you 3 for the help
Codeplug: using the 'call' instead the 'start /wait' have been solving the problem for the use of a bat file. That will be the default bat file for all the php interpret calls
Code:
@echo off
set php=%1
set font=%2
set out=%3
call %php% -f %font% >%out%
and the CreateProcess (without the inheritance changes) will be a simple
Code:
...
//here the structures setup are the same as on my last 3rd post
//because the problem was on the bat file
CreateProcess("mybatforphp.bat","path_to_php.exe path_to_font.php path_to_tmpoutput.html",NULL,NULL,0,0,NULL,NULL,&si,
&pi);
WaitForSingleObject(pi.hProcess,INFINITE);
//the bat have finished, so here I can access the output
...
So with that I can launch the bat file with some args that will call the php interpret, the bat will wait till the php interpret ends its job, and I'm able to wait till the bat ends its own.
@nthony: sure that the explanations on win32api man.ref. are right, but sometimes people reads between lines to speed up the job (and to obtain more errors and problems, like my case). I have made the corrections you point and now that method also works well:
Code:
#include <windows.h>
#include <stdio.h>
int main()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sap,sat,sao;
HANDLE out;
char bff[512];
//sec attributes for the output file
sao.nLength=sizeof(SECURITY_ATTRIBUTES);
sao.lpSecurityDescriptor=NULL;
sao.bInheritHandle=1;
//open the output file on the server's tmp folder (for that test will be on the C:/ root)
if((out=CreateFile("C:/output.html",GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,
&sao,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE)
{
printf("ERROR 0\n");
getchar();
return 0;
}
//init the STARTUPINFO struct
memset(&si,0,sizeof(si));
si.cb=sizeof(si);
//setup the redirection
si.dwFlags=STARTF_USESTDHANDLES;
si.hStdOutput=out;//for writing
si.hStdError=out;//for the errors, to the same file
//proc sec attributes
sap.nLength=sizeof(SECURITY_ATTRIBUTES);
sap.lpSecurityDescriptor=NULL;
sap.bInheritHandle=1;
//thread sec attributes
sat.nLength=sizeof(SECURITY_ATTRIBUTES);
sat.lpSecurityDescriptor=NULL;
sat.bInheritHandle=1;
//the requested file
sprintf(bff,"-f \"C:\\Documents and Settings\\Aeiou\\SERVIDOR\\dirweb\\demo.php\"");
//create the proc
if(!CreateProcess("C:\\PHP\\php-cgi.exe",bff,&sap,&sat,1,0,NULL,NULL,&si,&pi))
{
CloseHandle(out);
printf("ERROR 1\n");
getchar();
return 0;
}
//wait till the proc ends
WaitForSingleObject(pi.hProcess,INFINITE);
//close all
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(out);
getchar();
return 0;
}
anonytmouse: I'll have 'stolen' a trick from your code on the link you posted, the 'CREATE_NO_WINDOW' flag. What's that? Another non-documented win value? It doesn't appears on my copy of Win32PI Man.Ref, but it works.
If you don't mind, I'll use the CreateProcess with the inheritance flags on because in that way only 2 programs will run (the server and the php interpret, in the other case will be running the server, the bat and the php).
So, more thank's to that geat help.
Niara