how to use system to run more than 1 dos command?

This is a discussion on how to use system to run more than 1 dos command? within the C++ Programming forums, part of the General Programming Boards category; [code] #include <stdlib.h> int main(void) { system("cmd.exe"); system("dir/w"); system("cd debug"); return 0; } [\code] i run the program but only ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    how to use system to run more than 1 dos command?

    [code]
    #include <stdlib.h>

    int main(void)
    {
    system("cmd.exe");
    system("dir/w");
    system("cd debug");
    return 0;
    }
    [\code]

    i run the program but only the first command was ran,
    what's the problem??
    please help, thank you

  2. #2
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    To make sure all of them are ran try putting system("pause") inbetween each of the commands.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    still nothing happens

    after putting system("pause") in between ,it still remains the same.

    i am using visual c++ .net ,is it the problem?

  4. #4
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    well, dir /w waits for a user response, and you're not sending it one
    so pause won't matter, you need ot try regular dir or come up with a way to send a keypress to the dos box.
    PHP and XML
    Let's talk about SAX

  5. #5
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    What happens when you run it?

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    here it is

    [code]
    #include <stdlib.h>
    int main(void)
    {
    system("pause");
    system("dir/w\n");
    system("pause");
    system("cd\\Debug");
    system("pause");
    system("dir/w");
    }

    [\code]

    the problem is.....the command cd\\debug dun work, it said
    "the system cannot find the path specified"
    i have tried "cd debug", "cd\debug" but all are failed.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    in addition

    i know that the current directory in in c:\documents and settings .........\test, but i cant enter the directory "debug" inside,
    also i cant go back to the c drive

    what should be type in order to do so?

    thank you for helping

  8. #8
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    For changing your directory to debug just change the directory all at one time (make sure you spelled it right and you are doing it from its parent directory). And to change your directory to C:\ just use the command "cd \".

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    it failed

    i have tried that before , but fail when i build the project, error said :

    error c2001: newline in constrant line 7
    error c2146:syntax error:missing ) before system line 8

    it seems that the character "\" cant be reconised by c++, i wonder what should be substituted.

  10. #10
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    \\ or /

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    tried....still dun work

    i will try to find it out....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  3. how to run an exe command in c++ and get back the results?
    By mitilkhatoon in forum C++ Programming
    Replies: 5
    Last Post: 09-21-2006, 07:00 PM
  4. Run MFC exe from Command Line
    By magic.mike in forum Windows Programming
    Replies: 6
    Last Post: 09-08-2005, 03:00 PM
  5. Help in using variable in system command
    By moagim in forum C Programming
    Replies: 8
    Last Post: 08-26-2005, 09:12 AM

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