Unix Programming - capture output of exec

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2004 > capture output of exec





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author capture output of exec
vp

2004-01-24, 6:35 am

Sorry for this simply question.

My app needs to execute another app, such as ping. How can I get the
output of that app ?

Thanks,

DT
Jerry Feldman

2004-01-24, 6:35 am

On 24 Jan 2004 11:19:47 -0800
dt1649651@yahoo.com (vp) wrote:
quote:

> Sorry for this simply question.
>
> My app needs to execute another app, such as ping. How can I get the
> output of that app ?


You can use a pipe:
In C, use the popen(3) function.
From a shell script:
#!/bin/bash
$HOST=foo.bar.com
output=$(ping -c1 $HOST))
## the shell variable, output contains the output.

--
Jerry Feldman <gaf-nospam-at-blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Jens.Toerring@physik.fu-berlin.de

2004-01-24, 7:34 am

vp <dt1649651@yahoo.com> wrote:
quote:

> Sorry for this simply question.


quote:

> My app needs to execute another app, such as ping. How can I get the
> output of that app ?



If you want to thus from a C app have a look at the man page for
popen(3).
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.physik.fu-berlin.de/~toerring
vp

2004-01-24, 11:34 am

dt1649651@yahoo.com (vp) wrote in message news:<244097ab.0401241119.62b3d968@posting.google.com>...
quote:

> Sorry for this simply question.
>
> My app needs to execute another app, such as ping. How can I get the
> output of that app ?
>
> Thanks,
>
> DT



Thanks, Jerry and Jens.
That's popen() is what I want.

Thanks again,

DT
Hovik Melikyan

2004-01-25, 3:35 am


"vp" <dt1649651@yahoo.com> wrote in message
news:244097ab.0401241119.62b3d968@posting.google.com...
quote:

> Sorry for this simply question.
>
> My app needs to execute another app, such as ping. How can I get the
> output of that app ?
>



For a portable way of doing it (UNIX/Windows) in C++ take a look at

http://www.melikyan.com/ptypes/doc/ext/uexec/

-HM


Mohun Biswas

2004-01-25, 5:36 am

Hovik Melikyan wrote:
quote:

> "vp" <dt1649651@yahoo.com> wrote in message
> news:244097ab.0401241119.62b3d968@posting.google.com...
>
>
>
> For a portable way of doing it (UNIX/Windows) in C++ take a look at
>
> http://www.melikyan.com/ptypes/doc/ext/uexec/



Isn't popen portable UNIX/Windows? I'm using it on both platforms now.

MB

Hovik Melikyan

2004-01-25, 11:33 pm


"Mohun Biswas" <m.biswas@invalid.addr> wrote in message
news:RqUQb.19348$U%5.144493@attbi_s03...
quote:

> Hovik Melikyan wrote:
>
>
> Isn't popen portable UNIX/Windows? I'm using it on both platforms now.
>



True, but first PTypes is a "C++ way" (well, yet another one).

Second, it provides a framework for having kind of 'local' processes with
their main() functions as well - we call it 'units'. An external process is
only a special case of a unit in PTypes. Units are really threads with their
local input and output pipes. You can connect units to each other within
your process programmatically, as you do it in the Unix shell.

-HM


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com