C Shell RPC help


 
Thread Tools Search this Thread
Top Forums Programming C Shell RPC help
# 1  
Old 04-30-2009
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.
# 2  
Old 04-30-2009
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?
# 3  
Old 04-30-2009
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.
# 4  
Old 04-30-2009
Where does it echo anything to the shell??
Code:
$ 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?
# 5  
Old 04-30-2009
here is the layout of my files:

On the server PC:
server_program
shell_scrip

On the client PC:
client_program

shell_script
Code:
ls -l /

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

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

//and then comes the reading

# 6  
Old 04-30-2009
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)
Code:
$ ./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

# 7  
Old 04-30-2009
No i call ls from my terminal so it is normal that it will print something. Thanx very much for the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

RPC Error

Hi All, I am receiving RPC-Error 5 and sometimes RPC-Error 2 in my Hp-Ux servers. I have tried to kill and restart again.. Again same errors. Sometimes RPC process going down. Due to this other applications are not working in Hp ux servers. Kindly share some ideas for root cause... Or... (2 Replies)
Discussion started by: jakmani
2 Replies

2. Solaris

nfs mount: RPC: Rpcbind failure - RPC: Timed out

Fails to mount the server (10.125.224.22) during installation of a software on client, throwing the below error: nfs mount: 10.125.224.22: : RPC: Rpcbind failure - RPC: Timed out nfs mount: retrying: /cdrom This happened after complete shutdown of the lab. The server came up fine but most... (1 Reply)
Discussion started by: frintocf
1 Replies

3. Solaris

RPC: Rpcbind failure - RPC: Timed out error (solaris)

C: Rpcbind failure - RPC: Timed out error (solaris) hello an nfs server on my sun fire v440 is not responding , i get the error bellow and lots of my networking services are not reponding, please helppppp its an emergency RPC: Rpcbind failure - RPC: Timed out i also get NFS server... (2 Replies)
Discussion started by: feg
2 Replies

4. Solaris

Error : "RPC: Rpcbind failure - RPC: Timed out"

Hello I am having an issue with a server SUN FIRE T2000 (Solaris 10). First of all the server didn't boot normaly so I did a full restoration of the file systems. Now the server boot, most of the services are available (not all the services), but I keep on seeing RPC: Rpcbind failure -... (4 Replies)
Discussion started by: feg
4 Replies

5. Solaris

RPC: Rpcbind failure - RPC: Timed out

while i trying to mount from NAS i have this messages mount -F nfs -o rw 172.16.110.13:/tremabkup /tremabkup nfs mount: 172.16.110.13: : RPC: Rpcbind failure - RPC: Timed out nfs mount: retrying: /tremabkup nfs mount: 172.16.110.13: : RPC: Rpcbind failure - RPC: Timed out nfs mount:... (2 Replies)
Discussion started by: thecobra151
2 Replies

6. Linux

RPC Problem

:confused:Hi guys, The RPC problem is appearing on the screen while starting the portmap service,take a look of the real.. # service portmap restart Stopping portmap: Starting portmap: Cannot register... (1 Reply)
Discussion started by: daya.pandit
1 Replies

7. Red Hat

RPC Timeout

I have a RHEL 2.1 machine that I am trying to get to mount a remote nfs filesystem. Both servers have 2 network interfaces. My linux machine can mount the filesystem through one interface with no problems but if I switch over and try to mount it through the other interface using a totally... (1 Reply)
Discussion started by: darren.wyatt
1 Replies

8. Solaris

rpc.ttdbserverd

Recently,one of my Sun Box found this messages in the /var/adm/messages/ inetd: /usr/dt/bin/rpc.ttdbserverd: Hangup It had quite a number of the same message. If it related to any network issue? What is the purpose of rpc.ttdbserverd? Thanks (1 Reply)
Discussion started by: AirWalker83
1 Replies

9. UNIX for Dummies Questions & Answers

RPC service

Hi All, How can I add RPC service in SCO 5.0.7. I did not find in the sco cd please help me Alice (0 Replies)
Discussion started by: alisevA3
0 Replies

10. Programming

Rpc

Hello, I would like to do a program (in C) on which I would have to call 3 or more executables using execl command. But if the executables are situated on another machine say Y and I do a programe on the machine X, is it possible to invoke those executables (binaries) from the other machine... (1 Reply)
Discussion started by: driki
1 Replies
Login or Register to Ask a Question