TProcess.Parameters ? lazarus / 21-General ---------------------------------------------------------------------- Fred vS · 2021-03-29 01:47 Hello. How to translate that command line into a TProcess? Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ lspci -nn | grep -E 'VGA|Display' I did try with this but without luck, output is empty (without parameters it works but all is exported): 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 program ggd; uses   Classes, SysUtils, Process; var   AProcess: TProcess;  AStringList: TStringList; begin  AProcess := TProcess.Create(nil);  AProcess.Executable := '/usr/bin/lspci';   AProcess.Parameters.Add('-nn');   AProcess.Parameters.Add('|');   AProcess.Parameters.Add('grep');  AProcess.Parameters.Add('-E');  AProcess.Parameters.Add('''VGA|Display''');  AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];  AProcess.Execute;  AStringList := TStringList.Create;  AStringList.LoadFromStream(AProcess.Output);  AStringList.SaveToFile('output.txt');  AStringList.Free;  AProcess.Free;   end. Thanks. Fre;D ---------------------------------------------------------------------- lucamar · 2021-03-29 02:47 TProcess executes only one command but that command line needs two and something to pipe the exit from the first to the second, so you need to find some program which can 'run' the whole command line, i.e. a shell. Try this: 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 program ggd; uses  Classes, SysUtils, FileUtil, Process; var  AProcess: TProcess;  AStringList: TStringList; begin  AProcess := TProcess.Create(nil);  AProcess.Executable := FindDefaultExecutablePath('bash');  if AProcess.Executable <> '' then begin    AProcess.Parameters.Add('lspci');    AProcess.Parameters.Add('-nn');    AProcess.Parameters.Add('|');    AProcess.Parameters.Add('grep');    AProcess.Parameters.Add('-E ''VGA|Display''');    AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];    AProcess.Execute;    AStringList := TStringList.Create;    AStringList.LoadFromStream(AProcess.Output);  AStringList.SaveToFile('output.txt');    AStringList.Free;    AProcess.Free;  end;  end. I've taken the liberty of using FindDefaultExecutablePath() to make it search for it, rather than hard-coding a path, and of changing the first command from lpci to lspci, which I assumed is what you meant. There is still something wrong, because in this system it still returns nothing, but it's quite late here and my eyes are telling me to get to bed. ---------------------------------------------------------------------- Fred vS · 2021-03-29 03:03 Hola Lucamar. Thanks but output.txt is still empty  Quoteand of changing the first command from lpci to lspci, Huh, was it not lspci in previous post? Quoteit's quite late here and my eyes are telling me to get to bed. Yes, here too, many thanks Lucamar and have beautiful dreams. Fre;D ---------------------------------------------------------------------- marcov · 2021-03-29 05:45 The executable name must be the shell (like /bin/bash), the first parameter '-c'  and the third parameter the whole shell commandline without quotes. So 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 outstr : string;runcommand('/bin/bash',['-c','whole line | with other > redirections'],outstr); ---------------------------------------------------------------------- bytebites · 2021-03-29 06:19 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 aprocess: TProcess;begin    aprocess := TProcess.Create(nil);   aprocess.Executable := '/bin/sh';   aprocess.Parameters.Add('-c');   aprocess.Parameters.Add('/usr/bin/lspci | grep -E "VGA|Display"');   aprocess.Options := aprocess.Options + [poWaitOnExit, poUsePipes];   aprocess.Execute;     .... ---------------------------------------------------------------------- PascalDragon · 2021-03-29 06:59 Alternatively you can run only lspci and filter the output yourself: 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  outstr, s: String;  sl: TStringList;begin  RunCommand('lspci', [], outstr);  sl := TStringList.Create;  try    sl.Text := outstr;    outstr := '';    for s in sl do      if (Pos('VGA', s) > 0) or (Pos('Display', s) > 0) then        outstr := outstr + s + LineEnding;  finally    sl.Free;  end;end. ---------------------------------------------------------------------- Fred vS · 2021-03-29 12:47 Hello every body. @ Marcov: doing this: 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 runcommand('/bin/bash','-c',['lspci -nn | grep -E "VGA|Display|controller"'],outstr); gives this:  QuoteIncompatible type for arg no. 4: Got "AnsiString", expected "TProcessOptions" @ Bytebites: doing this: 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 aprocess := TProcess.Create(nil);   aprocess.Executable := '/bin/sh';   aprocess.Parameters.Add('-c');   aprocess.Parameters.Add('/usr/bin/lspci | grep -E "VGA|Display"');   aprocess.Options := aprocess.Options + [poWaitOnExit, poUsePipes];   aprocess.Execute;     AStringList := TStringList.Create;   AStringList.LoadFromStream(AProcess.Output);   AStringList.SaveToFile('output.txt');   AStringList.Free;   AProcess.Free; Produces exactly what wanted, big congrats. Quote00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (Whiskey Lake) (rev 02) @ Sven: Ok, your code works too, many thanks (but more tricky.) Many thanks to all and congratulation for the winner: bytebites Fre;D ---------------------------------------------------------------------- marcov · 2021-03-29 13:20 yeah there was a typo, I corrected my answer, the [ should be further to the left. ---------------------------------------------------------------------- Fred vS · 2021-03-29 14:04 Quote from: marcov on March 29, 2021, 03:20:29 pmyeah there was a typo, I corrected my answer, the [ should be further to the left. OK, you are still in the contest.  Now the result. Marcov's way: 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 program ggd_marcov; uses   Process, sysutils; function GetGraphicDriver(): string; var outstr : string;   begin   runcommand('/bin/bash',['-c','/usr/bin/lspci | grep -E "VGA|Display"'],outstr);     result := trim(outstr); end;    begin    writeln(GetGraphicDriver()); end. Comment: compact code, few units needed, size of binary: 253,8 k. Bytebites's way: 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 program ggd_bytebites; uses   Process, classes, sysutils; function GetGraphicDriver(): string; var   AProcess: TProcess;  AStringList: TStringList; begin   AProcess := TProcess.Create(nil);   AProcess.Executable := '/bin/sh';   AProcess.Parameters.Add('-c');   AProcess.Parameters.Add('/usr/bin/lspci | grep -E "VGA|Display"');   AProcess.Options := [poWaitOnExit, poUsePipes];   AProcess.Execute;  AStringList := TStringList.Create;   AStringList.LoadFromStream(AProcess.Output);   result := trim(AStringList[0]);   AStringList.Free;  end;   begin    writeln(GetGraphicDriver()); end. Comment: a few more lines needed and one unit more in uses, size of binary: 253,8 k. (exactly same as Marcov's way). Sven's way: 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 program ggd_sven; uses   Process, classes, sysutils; function GetGraphicDriver(): string;var  outstr, s: String;  sl: TStringList;begin  RunCommand('lspci', [], outstr);  sl := TStringList.Create;  try    sl.Text := outstr;    outstr := '';    for s in sl do      if (Pos('VGA', s) > 0) or (Pos('Display', s) > 0) then        outstr := outstr + s + LineEnding;           result := trim(outstr);       finally    sl.Free;  end;end;   begin    writeln(GetGraphicDriver());end. Comment: few more tricky and size of binary is 256,6 kb. (a few more Kb than the others). Conclusion: everybody wins (Marcov's way is the simplest but Bytebites answered to initial question). Thanks to all. Fre;D