Solved

newbie ?: how do i run external .exe and com files from a c program

Posted on 2004-04-06
7
623 Views
Last Modified: 2010-04-15
how do i run external .exe and com files from a c program. i also need to use switches when running these. so for instance i need to run a program like this "c:\command.com /c dir"
also how do i find out if a file or directory exists in c.
0
Comment
Question by:ico2
[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
  • 5
  • 2
7 Comments
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10763910
Hi, for running external programs ,u can use the system() command.

do this:
system("c:\command.com /c dir");

U can also use the execl(when u know how many separate arguments and execv(when u have variable arguments) functions

>how do i find out if a file or directory exists in c.
Use the findfirst() function
0
 
LVL 9

Accepted Solution

by:
ankuratvb earned 20 total points
ID: 10763934
/* findfirst and findnext example */

#include <stdio.h>
#include <dir.h>

int main(void)
{
   struct ffblk ffblk;
   int done;
   printf("Directory listing of *.*\n");
   //system("cd\");
   done = findfirst("*.*",&ffblk,0);
   while (!done)
   {
      printf("  %s\n", ffblk.ff_name);
      done = findnext(&ffblk);
   }
   return 0;
}
0
 
LVL 1

Author Comment

by:ico2
ID: 10763936
when i run that i get this error:
lexical: unknown escape sequence `\c'
'("a:\command.com /c dir")'
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 9

Expert Comment

by:ankuratvb
ID: 10763938
The above example is for dos.U have findfirst() and findnext() fns. in other platforms as well.
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10763943
Do this to search for files:
done = findfirst("find.txt",&ffblk,0);
0
 
LVL 1

Author Comment

by:ico2
ID: 10763959
thanks for the help ankuratvb. i now do not need to use command.com in my os.
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10763979
U'll have to use:
system("c:\\command.com /c dir");

To avoid the escape sequence.
0

Featured Post

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!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

751 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