Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

EXECVP and Output redirection

128 views
Skip to first unread message

Hasan Quadri

unread,
Mar 17, 1995, 3:37:50 AM3/17/95
to
I'm trying to use the EXECVP system call and what I'm trying to do is put the
output of the command that is run by EXECVP into a character buffer rather than
to the screen. Ex. I want to execute 'ls', I want its output to go into a
array of characters.
I've tried the DUP system call, but I can't get what I want. I'd really
appreciate some help on this, thanks.
--

Hasan Quadri "Windows isn't a virus, a virus does something!"
qua...@remus.rutgers.edu
http://remus.rutgers.edu/~quadri/index.html

Demetri Mouratis

unread,
Mar 18, 1995, 4:48:44 PM3/18/95
to
Hasan Quadri (qua...@remus.rutgers.edu) wrote:
| I'm trying to use the EXECVP system call and what I'm trying to do is put the
| output of the command that is run by EXECVP into a character buffer rather
| than
| to the screen. Ex. I want to execute 'ls', I want its output to go into a
| array of characters.
| I've tried the DUP system call, but I can't get what I want. I'd really
| appreciate some help on this, thanks.

If you want to use a system call to do this use pipe(), if you want to
use *FILE constructs, use popen(). Basically, they fork a child and
give you a file descriptor that you can use to read the output of the
child (for example, into a character array)

--
Demetri S. Mouratis ds...@hobbit.ntrs.com
The Northern Trust Company Voice: +1 312 630-0735
Chicago, IL 60675 FAX: +1 312 630-6797

"The mere act of drinking beer in an attempt to measure your tolerance
is likely to affect your impression of how many beers you've drunk."
-- The Heineken uncertainty principle.

Mischa Sandberg

unread,
Mar 18, 1995, 10:39:02 PM3/18/95
to
In article <1995Mar18....@news.ntrs.com>, ds...@hobbit.ntrs.com

(Demetri Mouratis) writes:
>
> If you want to use a system call to do this use pipe(), if you want to
> use *FILE constructs, use popen(). Basically, they fork a child and
> give you a file descriptor that you can use to read the output of the
> child (for example, into a character array)

Or, more explicitly:

char buf[999];
FILE *pp;

pp = popen("ls", "r");
if (pp == 0) exit(1);
while (fgets(buf, sizeof buf, pp) != 0) {
... do something with buf ...
}
pclose(pp);
--
Mischa Sandberg ... Mischa_...@mindlink.bc.ca
Engineers think equations approximate reality.
Physicists think reality approximates the equations.
Mathematicians never make the connection.

0 new messages