How to call/execute another .exe and get the return value?

How to call/execute another .exe and get the return value?

Post by Jeff Wa » Sun, 27 Oct 2002 09:48:36



I am writing a program which needs to call another program
to run and get the result.

The functions, system() or exec(), can triggle the other program,
foo.exe to run, however, how to get the return value of it, which is
a char string?  (Actually that program just fetches some database info
and display them, so I may re-code it to return a string). I don't want
to write the output into a file then retrive them.

It's under Unix enviroment, and C program. Please help!  Thanks!

Jeff

 
 
 

How to call/execute another .exe and get the return value?

Post by j.. » Sun, 27 Oct 2002 12:54:23



> I am writing a program which needs to call another program
> to run and get the result.

Sounds like you want popen(). Try running the command

man popen

 
 
 

How to call/execute another .exe and get the return value?

Post by Paul Pluzhniko » Sun, 27 Oct 2002 13:05:08



> The functions, system() or exec(), can triggle the other program,
> foo.exe to run, however, how to get the return value of it, which is
> a char string?  

Return value (aka exit code) *is* an int on all UNICes.

Quote:> (Actually that program just fetches some database info
> and display them, so I may re-code it to return a string). I don't want
> to write the output into a file then retrive them.

> It's under Unix enviroment, and C program. Please help!  Thanks!

What you want is not the return value, but the output.
Try "man popen"

Cheers,
--
In order to understand recursion you must first understand recursion.

 
 
 

How to call/execute another .exe and get the return value?

Post by Jeff Wa » Wed, 30 Oct 2002 01:37:55


Thanks very much! That's exactly what I want to use!


> > The functions, system() or exec(), can triggle the other program,
> > foo.exe to run, however, how to get the return value of it, which is
> > a char string?  

> Return value (aka exit code) *is* an int on all UNICes.

> > (Actually that program just fetches some database info
> > and display them, so I may re-code it to return a string). I don't want
> > to write the output into a file then retrive them.

> > It's under Unix enviroment, and C program. Please help!  Thanks!

> What you want is not the return value, but the output.
> Try "man popen"

> Cheers,

 
 
 

1. getting the return value of a command executed on another host

Folks,
I am doing a shell script in which I have to excute a command on another
host. I can do this by remsh.
So what I do is the typical remsh command
as in remsh hostname command
But what i want is the return value of the command that was executed on the
remot host. When I say echo $? it returns the value of the remsh command
which is successful. I tried this using a command which failed on the remote
host. but still I was gettin $? as 0 since the remsh command itself
succeeded. I am using ksh on HP-UX 10.2

Any pointers??

2. Vibra16C problems

3. Function Calls - Getting Return Value

4. Installing Linux Slackware Release from harddrive

5. Function Calls - Getting Return Value Part2

6. X Newbie asks about resolution/bit depth issue:

7. executing UNIX scripts from C, returning values

8. need help getting a Xircom PCMCIA ethernet card to work under freebsd 4.2

9. Bourne sh: Execute Command in "if" Condition and Negate Return Value?

10. Bugreport: the fstat call for pipes does not return the correct st_size value

11. System Call which Returns Executing Program Name?

12. Return value of msgsnd() system call

13. Q: Return-values of system("...") calls