Ver Mensaje Individual
  #1  
Antiguo 05-04-2017
Snaked Snaked is offline
Baneado
NULL
 
Registrado: sep 2016
Posts: 102
Reputación: 0
Snaked Va por buen camino
Question funcion para invocar comandos con fallos

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 newstdinnewstdoutread_stdoutwrite_stdin ;
unsigned int exitcod;
unsigned int bread;
unsigned int avail;

int Result 0;
if (
IsWinNT)
{
InitializeSecurityDescriptor(&sdSECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sdtrueNULLfalse);
sa.lpSecurityDescriptor = &sd;
}
else 
sa.lpSecurityDescriptor NULL;
sa.nLength sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle true;
  if (
CreatePipe(newstdinwrite_stdin, &sa0))
   {
     if (
CreatePipe(read_stdoutnewstdout, &sa0))
      {
         
GetStartupInfo(&si);

          
si.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
          
si.wShowWindow SW_HIDE;
           
si.hStdOutput newstdout;
           
si.hStdError newstdout;
           
si.hStdInput newstdin;

           
Fillchar(Buffersizeof(Buffer), 0);
             
GetEnvironmentVariable('COMSPEC', &Buffersizeof(Buffer) - 1);
         
StrCat(&Buffer,PChar(' /c ' Cmd));
      }
      if (
CreateProcess(NULL, &BufferNULLNULLtrueCREATE_NEW_CONSOLENULLNULLsipi)
      {
          while(
exitcod != STILL_ACTIVE && bread 0)
             {
               
PeekNamedPipe(read_stdout, @BufferSizeOf(Buffer) - 1, @bread, @availnil);
                if 
bread 0 then
                
{
                   
Fillchar(BufferSizeOf(Buffer), 0);
                   
ReadFile(read_stdoutBufferbreadbreadnil);
                   
Result Result String(PChar(&Buffer));
                 }
             }

Application.ProcessMessages;
GetExitCodeProcess(pi.hProcessexitcod);
      }
CloseHandle(read_stdout);
CloseHandle(newstdout);
end;
CloseHandle(newstdin);
CloseHandle(write_stdin);
    }
   } 
Responder Con Cita