C Shell RPC help

Hello everyone,

I am writing a rpc program, I have put the server program on a directory in another computer and i run the client program from my computer. I want that when i call a function in the server program it will have to execute a shell script and the retruning of the shell script be caught by the server program and sent back to my client to watch or manipulate.

And your question is? Do you need help with C? Sockets? Calling other programs? Capturing their output?
By the way, what's your program supposed to do that SSH can't?

i want to capture the output of a shell program from my C program calling it. Any ideas? I have used popen till now. Is there any other way, because i don't want the output from the shell to be echoed to the servers terminal.

Where does it echo anything to the shell??

$ cat process.c
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    FILE *proc, *out;
    char buffer[1024];

    proc = popen("/bin/ls /", "r");
    out = fopen("output.txt", "w");

    while (!feof(proc)) {
        fgets(buffer, 1024, proc);
        fprintf(out, "%s", buffer);
    }
    fclose(out);
    pclose(proc);

    return 0;
}
$ ./process
$ cat output.txt
bin
boot
dev
etc
home
lib
lost+found
media
mnt
opt
proc
root
sbin
srv
sys
tmp
usr
var
var

I still fail to understand what you're trying to accomplish, could you clarify that a bit more?

here is the layout of my files:

On the server PC:
server_program
shell_scrip

On the client PC:
client_program

shell_script

ls -l /

What happens is that i call with popen the ./shell_script the values are echoed to the servers terminal.

shell = popen("./shell_script", "r")

//and then comes the reading

Then you've either got one weird terminal setup (unless I'm mistaken, in which case I'm asking for enlightenment), or your shell script (or a program within) explicitly writes to the terminal, or your program still has some debug printf()'s in it writing to a term.

I couldn't reproduce your problem even with fork()ing and closing all (unneeded) file descriptors (code in attachment)

$ ./process
$ cat output.txt
bin
boot
dev
etc
home
lib
lost+found
media
mnt
opt
proc
root
sbin
srv
sys
tmp
usr
var
var
insgesamt 0
lr-x------ 1 pludi users 64 30. Apr 13:12 0 -> pipe:[1498244]
l-wx------ 1 pludi users 64 30. Apr 13:12 1 -> /tmp/testbed/output.txt
l-wx------ 1 pludi users 64 30. Apr 13:12 1 -> /tmp/testbed/output.txt

No i call ls from my terminal so it is normal that it will print something. Thanx very much for the help.