|
-
Dec 10th, 2002, 02:08 AM
#1
Thread Starter
New Member
Execute DOS Commands in C++ or C
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
-
Dec 10th, 2002, 03:49 AM
#2
Addicted Member
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
-
Dec 10th, 2002, 10:31 AM
#3
Frenzied Member
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().
-
Dec 10th, 2002, 02:21 PM
#4
Fanatic Member
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|