Recent

Author Topic: TProcess do command ?  (Read 1423 times)

scons

  • Full Member
  • ***
  • Posts: 141
TProcess do command ?
« on: December 15, 2017, 02:52:43 pm »
Hi all,

To simplify some things I'm trying to automate doing a lot of single (same) commands on a file list.

I normally would have to do something like "startexe parse -v -T filename" for all files in a folder.
My goal is to loop through a filelist and do this command on all files one by one.

I started with a Tprocess to call the main cmd window which is needed, this runs fine.

Code: Pascal  [Select][+][-]
  1.  var
  2.   CmdProgram: TProcess;
  3.  
  4. begin
  5.      CmdProgram := TProcess.Create(nil);
  6.       try
  7.         CmdProgram.CurrentDirectory := edithPath.Text;
  8.         CmdProgram.Executable := 'C:\folder\folder\folder\cmd.bat';
  9.         CmdProgram.Execute;
  10.       finally
  11.         CmdProgram.Free;
  12.       end;
  13. end;
  14.  

But now I need to start a command like "command parse -v -T filename" in the cmd window opened by the Tproces from above (a console window cmd.bat opens).

Do I need to start another TProcess for this ? Or is there some of extra function in TProcess that can pass/trigger this line ?

If I add parameters to the CmdProgram like:

Code: Pascal  [Select][+][-]
  1.  CmdProgram.Parameters.Add('command');
  2.  CmdProgram.Parameters.Add('parse');
  3.  CmdProgram.Parameters.Add('-v');
  4.  ...
  5.  

these do not have the correct effect (they do not show up in the created window) I believe they go to the first command -> cmd.bat, or am I passing them in a wrong way ?

Thanks
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: TProcess do command ?
« Reply #1 on: December 15, 2017, 05:29:08 pm »
hi,
as per the wiki you can receive some output from a TProcess run which maybe you could use on the next step.
Lazarus 2.0.2 64b on Debian LXDE 10

Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
Re: TProcess do command ?
« Reply #2 on: December 15, 2017, 05:40:17 pm »
hi,
as per the wiki you can receive some output from a TProcess run which maybe you could use on the next step.
You can receive you can receive ALL output from a TProcess . Both STDERR and STDOUT or pipes.
Specialize a type, not a var.

 

TinyPortal © 2005-2018