Reading Output from another program

Reading Output from another program

Post by Eric Phillip » Wed, 01 Jul 1998 04:00:00



Hello.  I need some help with something.  I would like to run the WHOIS
program in the background, and get the output from that program.  How
would I go about doing this in C?

--
Eric Phillips

 
 
 

Reading Output from another program

Post by Eric Phillip » Wed, 01 Jul 1998 04:00:00


That is the part that I need the help with.  Getting the stdout.  How do I
get that?  or how would I go about writing it to the file?




> >Hello.  I need some help with something.  I would like to run the WHOIS
> >program in the background, and get the output from that program.  How
> >would I go about doing this in C?

> I'm not that expert on this, but I would guess that one could
> use the C system function to execute the Unix whois command in the
> background writing its output to a file and then moving the file
> upon completion.  What the file contained would be indicative of
> success or failure, and it's existance would indicate completion.

> No doubt someone else will shread this approach, and give you a good
> answer.  :-)

> Chuck Demas
> Needham, Mass.

> --
>   Eat Healthy    |   _ _   | Nothing would be done at all,

>   Die Anyway     |    v    | That no one could find fault with it.


--
Eric Phillips


 
 
 

Reading Output from another program

Post by Charles Dem » Thu, 02 Jul 1998 04:00:00




Quote:>Hello.  I need some help with something.  I would like to run the WHOIS
>program in the background, and get the output from that program.  How
>would I go about doing this in C?

I'm not that expert on this, but I would guess that one could
use the C system function to execute the Unix whois command in the
background writing its output to a file and then moving the file
upon completion.  What the file contained would be indicative of
success or failure, and it's existance would indicate completion.

No doubt someone else will shread this approach, and give you a good
answer.  :-)

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.

 
 
 

Reading Output from another program

Post by Barry Margoli » Thu, 02 Jul 1998 04:00:00




Quote:>Hello.  I need some help with something.  I would like to run the WHOIS
>program in the background, and get the output from that program.  How
>would I go about doing this in C?

Use the popen(3) function.

--

GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.

 
 
 

Reading Output from another program

Post by Johan Hellstro » Thu, 02 Jul 1998 04:00:00





> >Hello.  I need some help with something.  I would like to run the WHOIS
> >program in the background, and get the output from that program.  How
> >would I go about doing this in C?

> Use the popen(3) function.

... or the underlying pipe(), close()-dup() or dup2().

/JAH

 
 
 

Reading Output from another program

Post by mattr.. » Thu, 02 Jul 1998 04:00:00


On Tue, 30 Jun 1998 17:54:17 +0000, Eric Phillips


>Hello.  I need some help with something.  I would like to run the WHOIS
>program in the background, and get the output from that program.  How
>would I go about doing this in C?

>--
>Eric Phillips


You should be able to use popen() to open a pipe connection to the
command you want to run.  It returns a FILE *, so you treat it just
like an fopen().

example:

FILE *whoiscmd = popen( "whois", "r" );
------
Matt

------
- These views are my own, not necessarily those of my company.

 
 
 

Reading Output from another program

Post by Mark Brow » Thu, 02 Jul 1998 04:00:00



> That is the part that I need the help with.  Getting the stdout.  How do I
> get that?  or how would I go about writing it to the file?

Since the string passed to system() is interpreted by a shell, you can
probably say

   system("command > file");

for appropriate command and file and read the file.  That said, it is
probably simpler and safer to use the Unix-specific popen().  There
are some examples of the use of popen() in the comp.unix.programmer
FAQ, which is avalible from
http://www.erlenstar.demon.co.uk/unix/faq_toc.html or via FTP from
rtfm.mit.edu.

--

            http://www.tardis.ed.ac.uk/~broonie/
EUFS        http://www.eusa.ed.ac.uk/societies/filmsoc/

 
 
 

Reading Output from another program

Post by Roger Boo » Fri, 03 Jul 1998 04:00:00


: That is the part that I need the help with.  Getting the stdout.  How do I
: get that?  or how would I go about writing it to the file?

I hate to just recommend a book, however, check out _Advanced Programming
in the UNIX Environment_ by Stevens, assuming you are doing this on
Unix.  Basicly it comes down to using fork() and dup().  If you need it
I have some code to do this (in C) but it is a bit much to post.

Roger
---------------------------------------------------------------------------
"Cryptography is like literacy in the Dark Ages. Infinitely potent, for
good and ill... yet basically an intellectual construct, an idea, which by
its nature will resist efforts to restrict it to bureaucrats and others who
deem only themselves worthy of such Privilege."
_ A thinking man's Creed for Crypto/ vbm.
---------------------------------------------------------------------------

 
 
 

1. program for read output of another program

Hello Unix's programmers,

        I think you can help me. I have a program which sometimes
write a message on a file (it appends that message). But now I want
to write a program which detect when  the program wrote any message
on the file.
        I wrote a program which read the file and show me the messages
already writen and save the index on a file of the last message. After
do this my program stay testing the file verifying if the size change.
But I think there is another way to do this, using pipes or others
unix features.  Does anybody have any idea?

        thanks in advance

                Delfim



2. memory space vs page space

3. Problem in Reading Program Output to a Shell Variable

4. Dail up problem in LAN

5. Read program output

6. Seyon can't see modem?

7. directing output of programs that are arguments of other programs

8. Can't format a floppy.

9. Howto capture output from external program run from C program

10. how to read disk read & write i/o through a c/c++ program ?

11. Help: Program to read from EOR end of last read?

12. Any programs to read and run MAI BASIC-4 programs?

13. Call a perl program and read the results back to/from a c program