[Solved] How is the pipeline transferred? lazarus / 34-Windows ---------------------------------------------------------------------- loaded · 2022-01-28 13:26 Hi All, How can we import the pipeline used in the command line in windows not into a file but into a memo? ---------------------------------------------------------------------- paweld · 2022-01-28 14:13 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);const  BufSize = 256;var  cmdprocess: TProcessUTF8;  ms: TMemoryStream;  NumBytes, BytesRead: Longint;begin  BytesRead := 0;  NumBytes := 0;  ms := TMemoryStream.Create;  cmdprocess := TProcessUTF8.Create(nil);  cmdprocess.Options := [poUsePipes, poNoConsole];  cmdprocess.Executable := 'cmd';  cmdprocess.Parameters.Add('/c');  cmdprocess.Parameters.Add('dir');  cmdprocess.Execute;  while cmdprocess.Running do  begin    ms.SetSize(BytesRead + BufSize);    NumBytes := cmdprocess.Output.Read((ms.Memory + BytesRead)^, BufSize);    if NumBytes > 0 then      Inc(BytesRead, NumBytes)    else      break;  end;  ms.SetSize(BytesRead);  memo1.Lines.LoadFromStream(ms);  ms.Free;  cmdprocess.Free;end;      More info: https://wiki.freepascal.org/Executing_External_Programs#Re ading_large_output You may also use: https://github.com/t-edson/UnTerminal ---------------------------------------------------------------------- engkin · 2022-01-28 14:21 The command is: Dir |yourApp Simply check StdInputHandle in your app. When used as above, StdInputHandle is not going to be 0. To read the data, use Windows API Or use THandleStream. Or Assign the handle to a text variable, and use ReadLn Edit: Sample code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  s:string;  hs: THandleStream;begin  if StdInputHandle>0 then  begin  hs:=THandleStream.Create(StdInputHandle);    SetLength(s,hs.Size);    hs.Read(s[1],hs.Size);    memo1.Text:=s; ---------------------------------------------------------------------- MarkMLl · 2022-01-28 14:24 The easiest way is to read what's available from Input (i.e. the preopened text device). I've done that in the past but would need to check the detail. The worst bit is getting your program to decide whether anything's actually being piped to it, or if it should e.g. rely on the standard dialog(u)e etc. to open a file. MarkMLl ---------------------------------------------------------------------- loaded · 2022-01-28 17:08 Thank you very much paweld and engkin and MarkMLl each for your replies. Inspired by the code and ideas you sent, I did a trial run. It works fine for the dos environment. I don't know if you have used it before!!! but not working with Ghostscript app !!! Is there anything else I can do about this? I would be glad if you can help. Respects. ---------------------------------------------------------------------- engkin · 2022-01-28 17:42 Use the command line version. I used GhostScript a few years ago, specifically I used the DLL. Edit: The command line version ends with the letter c. ---------------------------------------------------------------------- loaded · 2022-01-28 18:30 Quote from: engkin on January 28, 2022, 06:42:01 pmThe command line version ends with the letter c. Perfect spot, thank you very much engkin ---------------------------------------------------------------------- ASBzone · 2022-02-07 21:37 Quote from: engkin on January 28, 2022, 03:21:38 pmWhen used as above, StdInputHandle is not going to be 0. The problem is that StdInputHandle is often not 0, even when no piping is taking place. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$APPTYPE CONSOLE}{$MODE OBJFPC} program OpenPipe; begin  WriteLn('Standard Input Handle Value is: ', StdInputHandle);end.  Try this in Windows with the following commands: MyExe.exe DIR C:\ | MyExe.exe ---------------------------------------------------------------------- ASBzone · 2022-02-07 21:59 Also consider:  https://forum.lazarus.freepascal.org/index.php?topic=41936.0 ---------------------------------------------------------------------- engkin · 2022-02-07 23:20 Quote from: ASBzone on February 07, 2022, 10:37:24 pmQuote from: engkin on January 28, 2022, 03:21:38 pmWhen used as above, StdInputHandle is not going to be 0. The problem is that StdInputHandle is often not 0, even when no piping is taking place. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$APPTYPE CONSOLE}{$MODE OBJFPC} program OpenPipe; begin  WriteLn('Standard Input Handle Value is: ', StdInputHandle);end.  Try this in Windows with the following commands: MyExe.exe DIR C:\ | MyExe.exe Did you try with GUI apps? ---------------------------------------------------------------------- ASBzone · 2022-02-08 03:42 Quote from: engkin on February 08, 2022, 12:20:05 amDid you try with GUI apps? Nope... ---------------------------------------------------------------------- jcmontherock · 2022-02-08 09:51 What I am using: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  StringArray: TStringArray;  Line:         AnsiString;  FileStream:   TFileStream;  rc:           Boolean;....  StringArray := TStringArray.Create('/c', 'dir');  rc := RunCommand('cmd.exe', StringArray, Line, [poStderrToOutPut]);  if rc = False then WriteLn('Some error has been happend !...' + sLineBreak);  WriteLn('Command: ' + Line);   Memo1.Text := Line;   FileStream := TFileStream.Create('output.txt', fmCreate);  FileStream.Write(Line[1], Length(Line));  FileStream.Free;