GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Oct-2004, 14:04
Mr B Mr B is offline
New Member
 
Join Date: Oct 2004
Posts: 2
Mr B is on a distinguished road

reading the result of an external command


sounds simple, but can i get it?!!

i'm writing a small program, for which part of it's job will be to run other programs. these have text responses (return value is no good), but i cannot figure out how to read them!!

e.g.

external_program=check_whatever
return_text = system(external_program)

check_whatever dumps it's text on stdout, which ofcourse is to the screen. how can i read that response?

the above is what i want to achieve in laymans terms, but i cannot figure out how to do it. i dont want to use a tempfile (as my program can be potentially writing an burning 20 per second anyway because of the socket it is reading - dont ask lol, it's my bad coding )

i'm sure theres just one command to do it, but i'll be b&**^% if i can work it out - anyone know?

B
  #2  
Old 29-Oct-2004, 14:13
Mr B Mr B is offline
New Member
 
Join Date: Oct 2004
Posts: 2
Mr B is on a distinguished road
forgot to say

1/) debian linux
2/) C, not C++ (i think, how you tell)
3/) first post - um - hi!!

B

p.s. C baffles me, but shell script no problem, however it's inefficient, doesnt use message queues (which i neeed for IPC, however i have a freebee from the net for that ) and it cant handle sockets, unless someone knows how to do sockets under a shell ... as an example, flameproof.homeip.net , the stats page is a shell script, all home grown
  #3  
Old 29-Oct-2004, 18:06
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Mr B
sounds simple, but can i get it?!!

i'm writing a small program, for which part of it's job will be to run other programs. these have text responses (return value is no good), but i cannot figure out how to read them!!
Sounds simple it does. But to do isn't... (that's my Yoda impression)

Quote:
Originally Posted by Mr B
e.g.

external_program=check_whatever
return_text = system(external_program)

check_whatever dumps it's text on stdout, which ofcourse is to the screen. how can i read that response?

the above is what i want to achieve in laymans terms, but i cannot figure out how to do it. i dont want to use a tempfile (as my program can be potentially writing an burning 20 per second anyway because of the socket it is reading - dont ask lol, it's my bad coding )

i'm sure theres just one command to do it, but i'll be b&**^% if i can work it out - anyone know?

B
In general, no you can't do this. You exit the program with an integer status assigned to each error or message you output and the calling program looks at this value.

Alternative is when you output the information to the screen you also output it to a file which the calling program then reads.

In most cases the screen is not available to you, it hardware, so it's protected from direct access. And even if it wasn't, where would the text be? Top? Bottom? Where was the cursor when the program started?

I'd recommend the first as the easiest option, the second if you're outputting dynamic text (names, addresses) that will cahnge with each execution.
__________________

Age is unimportant -- except in cheese
  #4  
Old 30-Oct-2004, 06:51
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hello Mr B. Welcome to GIDForums™.

I have actually written a little tutorial that may (or may not) help. Using a inter process pipe you can connect one end to the stdout of a program and the other end to the stdin of a program. The calling mechanism used has to be the fork & spawn calls so that the pipe can be set up across both programs. Take a look here.

It is written in C, esp. for Linux. Not sure if that is exactly what you need, but you may be able to adapt it to work for you.

Good luck!
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[TUTORIAL] Calling an external program in C (Linux) dsmith C Programming Language 4 22-Apr-2005 13:30
Outputting function result to an array Shufty C Programming Language 4 07-May-2004 10:45
reading a char* into struct data spike666 C Programming Language 7 19-Apr-2004 12:06
including external libraries kenbrilliant C++ Forum 1 15-Dec-2003 13:06

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:52.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.