Results 1 to 4 of 4

Thread: Execute DOS Commands in C++ or C

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    13

    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

  2. #2
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    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

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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().

  4. #4
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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
  •  



Click Here to Expand Forum to Full Width