Recent

Author Topic: Execute external Programm with passing it Parameters ?  (Read 274 times)

Weitentaaal

  • Full Member
  • ***
  • Posts: 158
Execute external Programm with passing it Parameters ?
« on: January 29, 2021, 08:36:14 am »
Hello :)

Can i Use TProcess.CommandLine(#.exe param1 param2) like that ?
or is there some other way to execute external executables with params ?

Thanks for any reply :)
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

dsiders

  • Sr. Member
  • ****
  • Posts: 442
Re: Execute external Programm with passing it Parameters ?
« Reply #1 on: January 29, 2021, 08:44:47 am »
Hello :)

Can i Use TProcess.CommandLine(#.exe param1 param2) like that ?
or is there some other way to execute external executables with params ?

Thanks for any reply :)

Is there something that the docs did not cover?

https://www.freepascal.org/docs-html/current/fcl/process/tprocess.html
https://www.freepascal.org/docs-html/current/fcl/process/tprocess.executable.html
https://www.freepascal.org/docs-html/current/fcl/process/tprocess.parameters.html

Lazarus 2.0.12 / 2.1 (SVN) / FPC 3.0.4 / FPC 3.2.0 / x86-win64 / Windows 8.1

lucamar

  • Hero Member
  • *****
  • Posts: 3773
Re: Execute external Programm with passing it Parameters ?
« Reply #2 on: January 29, 2021, 08:47:41 am »
You can but CommandLine is deprecated and will probably dissapear soon. Instead, you should use Executable and Parameters.

See the FCL documentation, and the TProcess section in the wiki page on Executing External Programs to see them in use.

If for some reason you have to start from a full command line, you can find a couple helpful functions in LazFileUtils: SplitCmdLine() and SplitCmdLineParams()

HTH!
« Last Edit: January 29, 2021, 08:50:48 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Weitentaaal

  • Full Member
  • ***
  • Posts: 158
Re: Execute external Programm with passing it Parameters ?
« Reply #3 on: January 29, 2021, 08:57:24 am »
Thank You Guys :)
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9225
  • FPC developer.
Re: Execute external Programm with passing it Parameters ?
« Reply #4 on: January 29, 2021, 10:50:30 am »
And see if Runcommand satisfies your needs before rolling your own.

 

TinyPortal © 2005-2018