[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: A question.



Srinath Subbaramu, MS CIS forced the electrons to say:
> I have a small problem - may be a silly one.. :-(

Are these two problems, or one problem?

> I want to execute unix commands on a remote server, and print the output
> of the command on the client.  But, my problem is how to capture the
> output of the command.  

explore rsh, ssh etc. Check the man pages.

> I don't want to redirect the output to a file (system ("pwd > myfile");) 
> as it is very expensive to create the file, read from it and then delete
> it.

It is all that expensive, but of course, YMMV. :-)

What you can do is, pipe(), fork(), dup2() the child's stdout to the write end
of the pipe and execl() the command to run. The parent should be executing
read() on the pipe's read end. No disk involved, and you get the output of
your program. Of course, there are other issues, the parent should install a
handler for SIGCHLD, waitpid() in that handler etc. Check out Stevens' book
for more details.

Binand

-- 
main(int c,char **v){while(!fork()){strcpy(v[0],tmpnam(0));sleep(1);}}
A program that changes its name and pid every second.
Try this program at your own risk!   ---> Binand <---