Board index » delphi » FPC Linux - Running External Programs and Capturing Output

FPC Linux - Running External Programs and Capturing Output

Hi,

I am writing a server program in FPC on Linux. I need the ability to run a
program and capture its output into a variable. Much like the perl backticks
(``) or the system() command. exec() doesn't seem to work. Any suggestions?

   `Kevin Schachter

 .-- -- - --- -- -- - --- -- -- - --- -- -.
/\_   n s a n e   d o t   n e t              _/\
\/_/ - -- - --- - -- - --- - -- - --- - \_\/
      ke...@nsane.net
      http://www.nsane.net

 

Re:FPC Linux - Running External Programs and Capturing Output


Quote
kevin schachter wrote:

> Hi,

> I am writing a server program in FPC on Linux. I need the ability to run a
> program and capture its output into a variable. Much like the perl backticks
> (``) or the system() command. exec() doesn't seem to work. Any suggestions?

For this I create temporary files in say, /tmp for program output.. Just
use the > after the program you wish to execute and add the temp file
name.

There could be a better way but this works fine for me.

i.e

uses linux;
var
  errorcode:longint;
  shelloutput:TEXT;
  whateverstring:string;
..
..
..
errorcode:=shell('/sbin/ifconfig > /tmp/ifconfig.output');
assign(Shelloutput,'/tmp/ifconfig.output');
reset(shelloutput);
readln(shelloutput,whateverstring);

im not sure if i got the shell function right but i hope you get the
point

btw crossposting is a BAD idea

Re:FPC Linux - Running External Programs and Capturing Output


In article <3880CA84.1DD51...@penguinpowered.com>, Ketil Nordstad

Quote
<evil...@penguinpowered.com> wrote:
> > I am writing a server program in FPC on Linux. I need the ability to run a
> > program and capture its output into a variable. Much like the perl backticks
> > (``) or the system() command. exec() doesn't seem to work. Any suggestions?

[cut]

> btw crossposting is a BAD idea

Especially if it is also posted seperately to other groups
(comp.lang.pascal.misc). The question has been answered there for those
interested. "Followup-to" set.

Jonas

Other Threads