Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

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

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
anantb78
Asked:
anantb78
  • 4
1 Solution
 
mnashadkaCommented:
system returns the result, like in:
int x = system("bob.exe"); // x has the exit status
0
 
mnashadkaCommented:
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
 
mnashadkaCommented:
Actually, I think it's _popen and _pclose in Windows
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ExceterCommented:
>> 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
 
mnashadkaCommented:
>> 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
 
jmcgOwnerCommented:
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.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now