Recent

Author Topic: Result from shell command  (Read 484 times)

dryzone

  • Jr. Member
  • **
  • Posts: 50
Result from shell command
« on: February 27, 2025, 08:41:27 am »
program example56;

uses Unix;

With the manual example below I can obtain the exit status of a shell command.
Is it possible to read the result of the shell command into a string to be used in an fpk program ?

{ Program to demonstrate the Shell function }

Var S : Longint;

begin
  Writeln ('Output of ls -l *.pp');
  S:=fpSystem('ls -l *.pp');
  Writeln ('Command exited with status : ',S);
end.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8429
Re: Result from shell command
« Reply #1 on: February 27, 2025, 10:11:19 am »
Please put your program examples into code tags, otherwise they'll be mangled.

You can do what you want using TProcess, see the documentation and wiki.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Result from shell command
« Reply #2 on: February 27, 2025, 06:16:26 pm »
Alternatively and in addition to the already provided answer and in case only interested in the resulting output RunCommandInDir is an option. As indicated in the wiki as Executing External Programs to which was linked in a previous discussion about the same topic.

Using TProcess however provides more control over the whole process of executing an external program.
Today is tomorrow's yesterday.

dryzone

  • Jr. Member
  • **
  • Posts: 50
Re: Result from shell command
« Reply #3 on: March 07, 2025, 05:24:25 am »
Tron.
Thank you for the pointers, I will look into that. I looked in the manual but couldn't find anything.

 

TinyPortal © 2005-2018