The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help need to make a shell script run for ffmpeg vhook watermaking in shell wingchun22 Shell Programming and Scripting 1 09-27-2008 07:52 AM
Linux Shell Question: how to print the shell script name ? meili100 UNIX for Dummies Questions & Answers 3 07-01-2008 02:55 PM
How to Start a Shell as Login shell instead of ordinary shell Sivaswami Linux 3 07-01-2008 02:52 PM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-12-2006 03:27 AM
how to convert from korn shell to normal shell with this code? forevercalz Shell Programming and Scripting 21 11-23-2005 02:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-30-2009
ermalguni ermalguni is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 5
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 (permalink)  
Old 04-30-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,884
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 (permalink)  
Old 04-30-2009
ermalguni ermalguni is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 5
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 (permalink)  
Old 04-30-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,884
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 (permalink)  
Old 04-30-2009
ermalguni ermalguni is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 5
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 (permalink)  
Old 04-30-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,884
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
Attached Files
File Type: txt process.c.txt (752 Bytes, 17 views)
  #7 (permalink)  
Old 04-30-2009
ermalguni ermalguni is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 5
No i call ls from my terminal so it is normal that it will print something. Thanx very much for the help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0