Execute DOS Commands in C++?

This is a discussion on Execute DOS Commands in C++? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to use that DOS command to output a dir result to a text file. Is there any way ...

  1. #1
    Mike2432
    Guest

    Execute DOS Commands in C++?

    I'm trying to use that DOS command to output a dir result to a text file. Is there any way to execute the command through in my C++ program?

    If not, is there a way in C++ to get a list of all files in a directory?

    Thanks!

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Yes, there is:
    Code:
    #include <stdlib.h> 
    
    int main (int argc, char* argv[]) 
    { 
       system("dir C:\\temp > C:\\temp\\out.txt");
       return 0;
    }

  3. #3
    Mike2432
    Guest
    Great, thanks!

  4. #4
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    i thouhgt u need to include dos.h ? even tho it wouldnt make sense....
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Executing DOS commands from inside an image
    By Moony in forum C Programming
    Replies: 6
    Last Post: 03-16-2008, 12:40 PM
  2. Replies: 2
    Last Post: 07-27-2007, 12:48 PM
  3. Dos commands hehe
    By Carp in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-17-2003, 01:51 PM
  4. DOS Commands
    By Zuul in forum C++ Programming
    Replies: 11
    Last Post: 01-04-2002, 03:41 PM
  5. dos commands in c++
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-18-2001, 11:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21