?
Solved

calling an exe from a C program and using the value returned from it in DOS

Posted on 2003-03-14
7
Medium Priority
?
224 Views
Last Modified: 2010-04-15
Is there any way I can call an exe from a C program and use the value returned by the exe in DOS.
I know system() can be used but I cannot get the value returned by the exe in this case. Is there any alternate way.?

0
Comment
Question by:anantb78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 8

Expert Comment

by:mnashadka
ID: 8140227
system returns the result, like in:
int x = system("bob.exe"); // x has the exit status
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 8140234
If you need the console output of the window, you can use pipes; something like:
FILE *p;
char line[100];
p = popen("bob.exe", "r");
while(fgets(p, line))
{
  /* Do something */
}
pclose(p);
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 8140238
Actually, I think it's _popen and _pclose in Windows
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:Exceter
ID: 8141504
>> Actually, I think it's _popen and _pclose in Windows

Actually, I think that the underscores Microsoft specific. Although I could be mistaken. :-)

>> but I cannot get the value returned by the exe in this case.

Are you sure that the program you are calling returns int and not void? I.E. are you sure that this program returns a value?

Exceter
0
 
LVL 8

Accepted Solution

by:
mnashadka earned 200 total points
ID: 8142218
>> Actually, I think that the underscores Microsoft specific. Although I could be mistaken. :-)
Borland uses the _popen and _pclose as well.  anantb78 mentioned DOS, so I figure there's probably a 90%+ chance that he/she is using either the Microsoft or Borland compiler.  But you're right, not all compilers on Windows have the _'s (and I do come from a UNIX background where none of them do which is why the example code doesn't have them :) ).
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10123898
Nothing has happened on this question in more than 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by mnashadka.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question