[SOLVED]Getting console output as string lazarus / 1-Linux ---------------------------------------------------------------------- bobix · 2017-04-21 13:25 When i type in console 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 echo `ls`I'm getting list of files in current directory. But using Runcommand to get similar output, I am getting `ls` as string. How can I make echo to return list of files? Or is there any other way i can get, for example, output of this console command: xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_NAME 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 unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,process; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  ss:string;begin  ss:='';  runcommand('echo',['`ls`'],ss);  showmessage(ss);end; end. ---------------------------------------------------------------------- molly · 2017-04-21 13:34 runcommand/tprocess is not a shell. So you can not expect it to act as such. You do expect that with your code as it uses a chained command and backticks. Instead invoke bash and add parameters accordingly. That is a shell that should be capable of handling such things. More on executing external command can be found here. PS: if all you want is a directory listing why not use: Code: [Select]runcommand('ls',[],ss); ---------------------------------------------------------------------- bobix · 2017-04-21 13:52 I've tryed many things. Finaly got it working Thank you! 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);var  AProcess: TProcess;  AStringList: TStringList;begin  AProcess := TProcess.Create(nil);  AProcess.Executable := '/bin/sh';  AProcess.Parameters.Add('-c');  AProcess.Parameters.Add('echo `ls`');  AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];  AProcess.Execute;  AStringList := TStringList.Create;  AStringList.LoadFromStream(AProcess.Output);  showmessage(astringlist.Text) ;  AStringList.Free;  AProcess.Free;end;  "  AProcess.Parameters.Add('-c');" was the missing part in my tests ---------------------------------------------------------------------- molly · 2017-04-21 14:01 Good that you have it sorted out  For such specific cases it is always a good idea to refer to a manual that explains a few things. ---------------------------------------------------------------------- bobix · 2017-04-21 14:05 So true ---------------------------------------------------------------------- Leledumbo · 2017-04-23 03:55 Quote from: bobix on April 21, 2017, 03:52:57 pmI've tryed many things. Finaly got it working Thank you! ... "  AProcess.Parameters.Add('-c');" was the missing part in my tests This code is prone to buffer deadlock, better use runcommand or its brothers.