How to call an external command?

C

Cris Ding

Hi, everyone,

Now I need to execute an external command in my C program. For
example, the dos command is "lp_solve -p < LP1.txt". I want to execute
this command in my C program so as to obtain certain result, and then
continue to execute the C codes. But I have no idea how to manage it.
Could anyone please give me some hints one this problem? Thanks in
advance!

VB
/Cris
 
J

Joona I Palaste

Cris Ding said:
Hi, everyone,
Now I need to execute an external command in my C program. For
example, the dos command is "lp_solve -p < LP1.txt". I want to execute
this command in my C program so as to obtain certain result, and then
continue to execute the C codes. But I have no idea how to manage it.
Could anyone please give me some hints one this problem? Thanks in
advance!

You'll want system().
 
N

nrk

Cris said:
Hi, everyone,

Now I need to execute an external command in my C program. For
example, the dos command is "lp_solve -p < LP1.txt". I want to execute
this command in my C program so as to obtain certain result, and then
continue to execute the C codes. But I have no idea how to manage it.
Could anyone please give me some hints one this problem? Thanks in
advance!

VB
/Cris

You happen to be in luck. This is part of the CLC FAQ:

http://www.eskimo.com/~scs/C-faq/q19.27.html

Please take the time to read through the rest of the fine FAQ before posting
further questions:
http://www.eskimo.com/~scs/top.html

-nrk.
 
D

Derk Gwen

(e-mail address removed) (Cris Ding) wrote:
# Hi, everyone,
#
# Now I need to execute an external command in my C program. For
# example, the dos command is "lp_solve -p < LP1.txt". I want to execute
# this command in my C program so as to obtain certain result, and then
# continue to execute the C codes. But I have no idea how to manage it.
# Could anyone please give me some hints one this problem? Thanks in

You should look up the system() function.
rc = system("lp_solve -p < LP1.txt");
will parse the string, execute the command, and return a response code
if your system implements this function.
 
C

Cris Ding

Derk Gwen said:
(e-mail address removed) (Cris Ding) wrote:
# Hi, everyone,
#
# Now I need to execute an external command in my C program. For
# example, the dos command is "lp_solve -p < LP1.txt". I want to execute
# this command in my C program so as to obtain certain result, and then
# continue to execute the C codes. But I have no idea how to manage it.
# Could anyone please give me some hints one this problem? Thanks in

You should look up the system() function.
rc = system("lp_solve -p < LP1.txt");
will parse the string, execute the command, and return a response code
if your system implements this function.

OK, it works. Thank you guys very much!

VB
/Cris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top