Can someone please tell me what is the syntax of accessing a dos command using C or C++, for example, how can I call the command dir or del or DOS, from a C or C++:?
Thanks
Printable View
Can someone please tell me what is the syntax of accessing a dos command using C or C++, for example, how can I call the command dir or del or DOS, from a C or C++:?
Thanks
I think you can use system(command).
Or, if you are wanting to create a new process, you can do it using CreateProcess(). You can give CreateProcess the command line e.g. "dir c:\winnt" or something like that - look on msdn for more info.
HD
Code:#include <stdlib.h>
system("cls");
system("dir");
// these spawn a subprocess then execute the command.
// use _exec() or one of it's cousins to open a "DOS" window.
// you can also call CreateProcess() api or ShellExecute().
If you want to run a program, I like to use ShellExecute. If you want to use a dos command, you need to run the program cmd.exe (nt and xp) or command.com (95, 98, me) with the following parameters:
cmd /c <cmd>
command /c <cmd>
where <cmd> is the command you want to execute
(this is the method i used to use in vb)