necesito ayuda para esta funcion....sirve para invocar comandos de consola de windows pero sin que se muestre la ventana negra esa tan fea
la cosa es que lo he convertido de un codigo delphi y no he tenido mucha suerte
a ver si algun manitas puede arreglarmela para que funcione (creo que me he hecho el lio con los ifs y el do while repeat ese
Código PHP:
bool IsWinNT(void)
{
OSVERSIONINFO *OSV;
OSV->dwOSVersionInfoSize = sizeof(OSV);
GetVersionEx(OSV);
int Result = OSV->dwPlatformId;
return(Result);
}
void CmdExec(AnsiString Cmd)
{
char Buffer[4096];
STARTUPINFO si;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
PROCESS_INFORMATION pi;
THandle newstdin, newstdout, read_stdout, write_stdin ;
unsigned int exitcod;
unsigned int bread;
unsigned int avail;
int Result = 0;
if (IsWinNT)
{
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;
if (CreatePipe(newstdin, write_stdin, &sa, 0))
{
if (CreatePipe(read_stdout, newstdout, &sa, 0))
{
GetStartupInfo(&si);
si.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.hStdOutput = newstdout;
si.hStdError = newstdout;
si.hStdInput = newstdin;
Fillchar(Buffer, sizeof(Buffer), 0);
GetEnvironmentVariable('COMSPEC', &Buffer, sizeof(Buffer) - 1);
StrCat(&Buffer,PChar(' /c ' + Cmd));
}
if (CreateProcess(NULL, &Buffer, NULL, NULL, true, CREATE_NEW_CONSOLE, NULL, NULL, si, pi)
{
while(exitcod != STILL_ACTIVE && bread = 0)
{
PeekNamedPipe(read_stdout, @Buffer, SizeOf(Buffer) - 1, @bread, @avail, nil);
if bread > 0 then
{
Fillchar(Buffer, SizeOf(Buffer), 0);
ReadFile(read_stdout, Buffer, bread, bread, nil);
Result = Result + String(PChar(&Buffer));
}
}
Application.ProcessMessages;
GetExitCodeProcess(pi.hProcess, exitcod);
}
CloseHandle(read_stdout);
CloseHandle(newstdout);
end;
CloseHandle(newstdin);
CloseHandle(write_stdin);
}
}