Thread: How to retrieve the output of an external program?

How to retrieve the output of an external program?

From
"Jean-Yves F. Barbier"
Date:
Hi list & happy easter,

What I'd like to be able to do is:
* Run a function that sends parms to an external pgm [no PB],
* Capture the external pgm output that normally goes to stdout.

Is it possible directly or am I obliged to use a temporary file
and retrieve it from my function?

JY
--
                printk("ufs_read_super: fucking Sun blows me\n");
        -- /usr/src/linux/fs/ufs/ufs_super.c

Re: How to retrieve the output of an external program?

From
Michael Wood
Date:
On 8 January 2012 19:29, Jean-Yves F. Barbier <12ukwn@gmail.com> wrote:
> Hi list & happy easter,

It's a bit too early for that, isn't it?  Perhaps you meant Valentine's Day? :)

> What I'd like to be able to do is:
> * Run a function that sends parms to an external pgm [no PB],
> * Capture the external pgm output that normally goes to stdout.
>
> Is it possible directly or am I obliged to use a temporary file
> and retrieve it from my function?

I'm not sure, since I've never tried something like this in Postgres,
but perhaps pipe(2), dup2(2), and one of exec*(3) will help?

I haven't read through these, but they might help too:
http://stackoverflow.com/questions/3382485/reading-child-process-output-as-soon-as-some-is-available
http://ubuntuforums.org/archive/index.php/t-1627614.html
http://stackoverflow.com/questions/3835905/redirecting-forked-process-output-to-parent-process-in-c
http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_10.html

--
Michael Wood <esiotrot@gmail.com>

Re: How to retrieve the output of an external program?

From
"Jean-Yves F. Barbier"
Date:
On Sun, 8 Jan 2012 22:40:04 +0200
Michael Wood <esiotrot@gmail.com> wrote:

> On 8 January 2012 19:29, Jean-Yves F. Barbier <12ukwn@gmail.com> wrote:
> > Hi list & happy easter,
>
> It's a bit too early for that, isn't it?  Perhaps you meant Valentine's Day? :)

Oops, I meant happy turkey of independence that lay easter eggs:)

…
> I haven't read through these, but they might help too:
> http://stackoverflow.com/questions/3382485/reading-child-process-output-as-soon-as-some-is-available

Yes Mike, this should do the trick, thanks.

JY
--
A private sin is not so prejudicial in the world as a public
indecency. -- Miguel de Cervantes