Ver Mensaje Individual
  #4  
Antiguo 06-04-2017
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Reputación: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Cita:
Empezado por Snaked Ver Mensaje
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);
    }
   } 
Y partiendo de una función publicada en el mismo foro, ¿no crees que hubiese sido elegante citar la fuente y su autor? Ejecutar comando y capturar su salida (Domingo Seoane)

Saludos.
Responder Con Cita