Reputation: 95
I need to make 2 programs communicating with each other using pipes. First program save's it's path in a pipe and sends it to second, which should run ls
command with that path and send back the output of ls
. I wanted to send like this write(fd2, arr2, strlen(arr2)+1);
where fd2
is is an integer that contains descriptor. I wanted to execvp("ls ", argv);
and assign it's output to arr2
, but i don't know how to do this without additions files.
EDIT
Basically the problem is:
How to save the output of execvp("ls ", argv);
in an array?
Upvotes: 1
Views: 533
Reputation: 1352
execvp
doesn't have an output value (as the fact of returning from an exec
function is an indication of an error).
If you want to have only the output, use popen
.
If you want more control (or want to redirect both in and out), read on.
Assuming you want to grab the output of a program you run in exec
, you need to do the following:
pipe()
)fork()
dup2
)exec()
Upvotes: 1