Link to home
Start Free TrialLog in
Avatar of ico2
ico2

asked on

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.
Avatar of ankuratvb
ankuratvb
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of ankuratvb
ankuratvb
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ico2
ico2

ASKER

when i run that i get this error:
lexical: unknown escape sequence `\c'
'("a:\command.com /c dir")'
The above example is for dos.U have findfirst() and findnext() fns. in other platforms as well.
Do this to search for files:
done = findfirst("find.txt",&ffblk,0);
Avatar of ico2

ASKER

thanks for the help ankuratvb. i now do not need to use command.com in my os.
U'll have to use:
system("c:\\command.com /c dir");

To avoid the escape sequence.