Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus-es / 2013-08

Problema con texto generado desde tprocess

10 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

metal box

Buenas, viendo que han estado hablando sobre la esto tengo un peque�o problema.

Genero un texto desde tprocess utilizando wmic para obtener algunos valores del sistema pero cuando trato de recuperar el valor del archivo de text o me aparece ??NE o solo cuadritos, el problema es que no me deja leer nada, pero cuando abro el archivo de texto con bloc de notas se ve correctamente, aque se puede deber esto?

Con este codigo leeo el archivo, archivos creados sin utilizar wmic si los lee.

var F: TextFile;
    sLinea: String;
begin
  AssignFile( F, ExtractFilePath( Application.ExeName ) + 'prueba.txt' );
  Reset( F );
  while not Eof( F ) do
  begin
    ReadLn( F, sLinea );
    Memo1.Lines.Add( sLinea );
  end;
  CloseFile( F );
*Saludos. Jose Daboin* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130802/c6fefc73/attachment.html>

Reply by email

Martin Gomez
to metal box

Estaras generando el texto en UTF-8?

2013/8/2 metal box <metalbox9000 en gmail.com>

Show quoted text 37 lines
Buenas, viendo que han estado hablando sobre la esto tengo un peque�o problema. Genero un texto desde tprocess utilizando wmic para obtener algunos valores del sistema pero cuando trato de recuperar el valor del archivo de text o me aparece ??NE o solo cuadritos, el problema es que no me deja leer nada, pero cuando abro el archivo de texto con bloc de notas se ve correctamente, aque se puede deber esto? Con este codigo leeo el archivo, archivos creados sin utilizar wmic si los lee. var F: TextFile; sLinea: String; begin AssignFile( F, ExtractFilePath( Application.ExeName ) + 'prueba.txt' ); Reset( F ); while not Eof( F ) do begin ReadLn( F, sLinea ); Memo1.Lines.Add( sLinea ); end; CloseFile( F ); -- *Saludos. Jose Daboin* _______________________________________________ Lazarus-es mailing list Lazarus-es en lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es
Try not to become a man of success but rather to become a man of value. *Albert Einstein* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130802/eaf667fb/attachment.html>

Reply by email

metal box
to Martin Gomez

Pues directamente lo hago utilizando cmd wmic elvaorquebusco >>texto.txt

El 2 de agosto de 2013 16:47, Martin Gomez <mmgomez en gmail.com> escribi�:

Show quoted text 54 lines
Estaras generando el texto en UTF-8? 2013/8/2 metal box <metalbox9000 en gmail.com> > Buenas, viendo que han estado hablando sobre la esto tengo un peque�o > problema. > > Genero un texto desde tprocess utilizando wmic para obtener algunos > valores del sistema pero cuando trato de recuperar el valor del archivo de > text o me aparece ??NE o solo cuadritos, el problema es que no me deja > leer nada, pero cuando abro el archivo de texto con bloc de notas se ve > correctamente, aque se puede deber esto? > > Con este codigo leeo el archivo, archivos creados sin utilizar wmic si > los lee. > > var F: TextFile; > sLinea: String; > begin > AssignFile( F, ExtractFilePath( Application.ExeName ) + 'prueba.txt' ); > Reset( F ); > > while not Eof( F ) do > begin > ReadLn( F, sLinea ); > Memo1.Lines.Add( sLinea ); > end; > > CloseFile( F ); > > -- > *Saludos. > > Jose Daboin* > > _______________________________________________ > Lazarus-es mailing list > Lazarus-es en lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es > > -- Try not to become a man of success but rather to become a man of value. *Albert Einstein* _______________________________________________ Lazarus-es mailing list Lazarus-es en lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es
*Saludos. Jose Daboin* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130802/da8fe779/attachment.html>

Reply by email

metal box
to metal box

La cosa es que si abro el archivo de texto con bloc de notas y se ve normal pero al pasarlo a un memo me aparece ??N

El 2 de agosto de 2013 17:20, metal box <metalbox9000 en gmail.com> escribi�:

Show quoted text 66 lines
Pues directamente lo hago utilizando cmd wmic elvaorquebusco >>texto.txt El 2 de agosto de 2013 16:47, Martin Gomez <mmgomez en gmail.com> escribi�: Estaras generando el texto en UTF-8? > > > 2013/8/2 metal box <metalbox9000 en gmail.com> > >> Buenas, viendo que han estado hablando sobre la esto tengo un peque�o >> problema. >> >> Genero un texto desde tprocess utilizando wmic para obtener algunos >> valores del sistema pero cuando trato de recuperar el valor del archivo de >> text o me aparece ??NE o solo cuadritos, el problema es que no me deja >> leer nada, pero cuando abro el archivo de texto con bloc de notas se ve >> correctamente, aque se puede deber esto? >> >> Con este codigo leeo el archivo, archivos creados sin utilizar wmic si >> los lee. >> >> var F: TextFile; >> sLinea: String; >> begin >> AssignFile( F, ExtractFilePath( Application.ExeName ) + 'prueba.txt' ); >> Reset( F ); >> >> while not Eof( F ) do >> begin >> ReadLn( F, sLinea ); >> Memo1.Lines.Add( sLinea ); >> end; >> >> CloseFile( F ); >> >> -- >> *Saludos. >> >> Jose Daboin* >> >> _______________________________________________ >> Lazarus-es mailing list >> Lazarus-es en lists.lazarus.freepascal.org >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es >> >> > > > -- > Try not to become a man of success but rather to become a man of value. *Albert > Einstein* > > _______________________________________________ > Lazarus-es mailing list > Lazarus-es en lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es > > -- *Saludos. Jose Daboin*
*Saludos. Jose Daboin* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130802/b0379bc4/attachment.html>

Reply by email

Martin Gomez
to metal box: Pues directamente lo hago utilizando cmd wmic elvaorquebusco >>texto.txt El 2 de agosto…

2013/8/2 metal box <metalbox9000 en gmail.com>

Pues directamente lo hago utilizando cmd wmic elvaorquebusco >>texto.txt

?Si pones en options "usePipes" y sigues el ejemplo de aca: ? http://wiki.freepascal.org/Executing_External_Programs/es#Lectura_de_muchos_datos_de_salida

debieses levantarlo sin problemas, y sin un archivo intermedio.?

Try not to become a man of success but rather to become a man of value. *Albert Einstein* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130802/46df3000/attachment.html>

Reply by email

metal box
to Martin Gomez

Bueno, gracias de todos modos pero me encontre una funcion que obtiene el valor de salida y lo guado desde un memo y al cargar funciona correctamente.

El 2 de agosto de 2013 17:26, Martin Gomez <mmgomez en gmail.com> escribi�:

Show quoted text 22 lines
2013/8/2 metal box <metalbox9000 en gmail.com> > Pues directamente lo hago utilizando cmd wmic elvaorquebusco >>texto.txt Si pones en options "usePipes" y sigues el ejemplo de aca: http://wiki.freepascal.org/Executing_External_Programs/es#Lectura_de_muchos_datos_de_salida debieses levantarlo sin problemas, y sin un archivo intermedio. -- Try not to become a man of success but rather to become a man of value. *Albert Einstein* _______________________________________________ Lazarus-es mailing list Lazarus-es en lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es
*Saludos. Jose Daboin* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130803/77a3a464/attachment.html>

Reply by email

Martin Gomez
to metal box

2013/8/3 metal box <metalbox9000 en gmail.com>

Bueno, gracias de todos modos pero me encontre una funcion que obtiene el valor de salida y lo guado desde un memo y al cargar funciona correctamente.

?Y cual ser�a esa funci�?n?
Yo uso la del ejemplo que envi� y me resulta, pero quiz�s la tuya sea mas simple?

Try not to become a man of success but rather to become a man of value. *Albert Einstein* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130803/6e347592/attachment.html>

Reply by email

metal box
to Martin Gomez
function CmdExec(Cmd: string): string;
{
ESTA FUNCION MUESTRA LA SALIDA DE CMD
EJEMPLO
SHOWMESSAGE(CmdExec(echo hola))
}
var
  Buffer: array[0..4096] of Char;
  si: STARTUPINFO;
  sa: SECURITY_ATTRIBUTES;
  sd: SECURITY_DESCRIPTOR;
  pi: PROCESS_INFORMATION;
  newstdin, newstdout, read_stdout, write_stdin: THandle;
  exitcod, bread, avail: Cardinal;
begin
  Result:= '';
  if IsWinNT then
  begin
    InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION);
    SetSecurityDescriptorDacl(@sd, true, nil, false);
    sa.lpSecurityDescriptor := @sd;
  end
  else sa.lpSecurityDescriptor := nil;
  sa.nLength := sizeof(SECURITY_ATTRIBUTES);
  sa.bInheritHandle := TRUE;
  if CreatePipe(newstdin, write_stdin, @sa, 0) then
  begin
    if CreatePipe(read_stdout, newstdout, @sa, 0) then
    begin
      GetStartupInfo(si);
      with si do
      begin
        dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
        wShowWindow := SW_HIDE;
        hStdOutput := newstdout;
        hStdError := newstdout;
        hStdInput := newstdin;
      end;
      Fillchar(Buffer, SizeOf(Buffer), 0);
      GetEnvironmentVariable('COMSPEC', @Buffer, SizeOf(Buffer) - 1);
      StrCat(@Buffer,PChar(' /c ' + Cmd));
      if CreateProcess(nil, @Buffer, nil, nil, TRUE, CREATE_NEW_CONSOLE,
nil, nil, si, pi) then
      begin
        repeat
          PeekNamedPipe(read_stdout, @Buffer, SizeOf(Buffer) - 1, @bread,
@avail, nil);
          if bread > 0 then
          begin
            Fillchar(Buffer, SizeOf(Buffer), 0);
            ReadFile(read_stdout, Buffer, bread, bread, nil);
            Result:= Result + String(PChar(@Buffer));
          end;
          Application.ProcessMessages;
          GetExitCodeProcess(pi.hProcess, exitcod);
        until (exitcod  STILL_ACTIVE) and (bread = 0);
      end;
      CloseHandle(read_stdout);
      CloseHandle(newstdout);
    end;
    CloseHandle(newstdin);
    CloseHandle(write_stdin);
  end;
end;

Como vez alli en la funcion StrCat colocan CMD por lo que asi como esta funciona solo en windows no se si podria funcionar con la consola de linux.

Una Pregunta windows 8 Trae CMD o lo eliminaron totalmente por el nuevo shell

El 3 de agosto de 2013 19:52, Martin Gomez <mmgomez en gmail.com> escribi�:

Show quoted text 24 lines
2013/8/3 metal box <metalbox9000 en gmail.com> > Bueno, gracias de todos modos pero me encontre una funcion que obtiene el > valor de salida y lo guado desde un memo y al cargar funciona correctamente. Y cual ser�a esa funci�n? Yo uso la del ejemplo que envi� y me resulta, pero quiz�s la tuya sea mas simple? -- Try not to become a man of success but rather to become a man of value. *Albert Einstein* _______________________________________________ Lazarus-es mailing list Lazarus-es en lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es
*Saludos. Jose Daboin* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130804/aee92991/attachment.html>

Reply by email

Martin Gomez
to metal box
metal box wrote
Como vez alli en la funcion StrCat colocan CMD por lo que asi como esta funciona solo en windows no se si podria funcionar con la consola de linux.

me resulta demasiado complicada tu solucion :)
Yo uso TProcess de esta manera:

  Proceso := TProcess.Create(nil);
  Proceso.Executable := FindDefaultExecutablePath('synce-pcp');
  with Proceso.Parameters do
  begin
    Add(':' + csSource);
    Add(csTarget);
  end;
  Proceso.Options := Proceso.Options + [poWaitOnExit, poUsePipes,
poStderrToOutPut];
  Proceso.Execute;
  LogStream(Proceso.Output);
  Result := Proceso.ExitStatus;
  if Result  0 then
    ShowMessage('error copiando "' + csTarget + '"');
  Proceso.Free;

Siendo LogStream lo siguiente:

procedure LogStream(Stream: TStream);
var
  Lista: TStringList;
  j: integer;
begin
  Lista := TStringList.Create;
  try
    Lista.LoadFromStream(Stream);
    for j := 0 to Lista.Count - 1 do
    begin
      DebugLn([DateTimeToStr(Now), '  = ', Lista[j]]);
    end;
  finally
    Lista.Free;
  end;
end;

O sea, obtengo el resultado de la ejecucion y lo envio a debug (pero vos podes hacer lo que necesites con el resultado)

Una Pregunta windows 8 Trae CMD o lo eliminaron totalmente por el nuevo shell

?Aun existe.?

Try not to become a man of success but rather to become a man of value. *Albert Einstein* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130805/c0092229/attachment.html>

Reply by email

metal box
to Martin Gomez

ok, si me parece muchisimo mejor, la otra funcion que deje es un poco lenta.

2013/8/5 Martin Gomez <mmgomez en gmail.com>

Show quoted text 69 lines
On Sun, Aug 4, 2013 at 1:40 PM, metal box <metalbox9000 en gmail.com> wrote: > Como vez alli en la funcion StrCat colocan CMD por lo que asi como esta > funciona solo en windows no se si podria funcionar con la consola de linux. > me resulta demasiado complicada tu solucion :) Yo uso TProcess de esta manera: Proceso := TProcess.Create(nil); Proceso.Executable := FindDefaultExecutablePath('synce-pcp'); with Proceso.Parameters do begin Add(':' + csSource); Add(csTarget); end; Proceso.Options := Proceso.Options + [poWaitOnExit, poUsePipes, poStderrToOutPut]; Proceso.Execute; LogStream(Proceso.Output); Result := Proceso.ExitStatus; if Result 0 then ShowMessage('error copiando "' + csTarget + '"'); Proceso.Free; Siendo LogStream lo siguiente: procedure LogStream(Stream: TStream); var Lista: TStringList; j: integer; begin Lista := TStringList.Create; try Lista.LoadFromStream(Stream); for j := 0 to Lista.Count - 1 do begin DebugLn([DateTimeToStr(Now), ' = ', Lista[j]]); end; finally Lista.Free; end; end; O sea, obtengo el resultado de la ejecucion y lo envio a debug (pero vos podes hacer lo que necesites con el resultado) > Una Pregunta windows 8 Trae CMD o lo eliminaron totalmente por el nuevo > shell > Aun existe. -- Try not to become a man of success but rather to become a man of value. *Albert Einstein* _______________________________________________ Lazarus-es mailing list Lazarus-es en lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus-es
*Saludos. Jose Daboin* ------------ pr�xima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus-es/attachments/20130810/8128fcae/attachment.html>

Reply by email