Go Premium for a chance to win a PS4. Enter to Win

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

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

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
ico2
Asked:
ico2
  • 5
  • 2
1 Solution
 
ankuratvbCommented:
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
 
ankuratvbCommented:
/* 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
 
ico2Author Commented:
when i run that i get this error:
lexical: unknown escape sequence `\c'
'("a:\command.com /c dir")'
0
Independent Software Vendors: 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!

 
ankuratvbCommented:
The above example is for dos.U have findfirst() and findnext() fns. in other platforms as well.
0
 
ankuratvbCommented:
Do this to search for files:
done = findfirst("find.txt",&ffblk,0);
0
 
ico2Author Commented:
thanks for the help ankuratvb. i now do not need to use command.com in my os.
0
 
ankuratvbCommented:
U'll have to use:
system("c:\\command.com /c dir");

To avoid the escape sequence.
0

Featured Post

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.

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