!!Using the sytem() fuction to call a commad

This is a discussion on !!Using the sytem() fuction to call a commad within the C++ Programming forums, part of the General Programming Boards category; how would i use dos.h to call a system command like dir or copy or some other inferior command like ...

  1. #1
    Unregistered
    Guest

    !!Using the sytem() fuction to call a commad

    how would i use dos.h to call a system command like dir or copy or some other inferior command like that? OR were can i get a tutorial for using the dos.h header file?

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    system(); is not defined in dos.h, but it IS defined in stdlib.h
    i'll show u a quick example:

    Code:
    #include <conio.h> // for getch()
    #include <stdlib.h> // for system()
    #include <iostream> // for cout
    using namespace std;
    
    int main(int argc, char *argv[])
    {
         cout << "Press any key and watch in amazement as the contents of this directory apear on your screen!";
         getch();
         system("DIR");
         getch();
         return 0;
    }
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  3. #3
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    i dont think this one is in dos.h but to do dos commands use

    system("command");

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    I tried that...

    Code:
    #include <conio.h> // for getch()
    #include <stdlib.h> // for system()
    #include <iostream> // for cout
    using namespace std;
    
    int main(int argc, char *argv[])
    {
         cout << "Press any key and watch in amazement as the contents of this directory apear on your screen!";
         getch();
         system("DIR");
         getch();
         return 0;
    }
    [/B]
    it didn't work, but I have got the idea...
    thanx
    C++
    The best

  5. #5
    Registered User unknownUser's Avatar
    Join Date
    Apr 2002
    Posts
    14

    yes but...

    how would u do like if u typed ls into your program and then it ran dir.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Question What do you mean....

    You mean " ls" in LUNIX"
    C++
    The best

  7. #7
    Registered User unknownUser's Avatar
    Join Date
    Apr 2002
    Posts
    14

    YES

    yes i am making a program for school that if u type in linux commands it does the DOS equivalent

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >> it didn't work, but I have got the idea...
    It didnt? what compiler are u using? It worked perfectly fine on mine (Visual C++ 6.0)
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  9. #9
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    hey where could I find all the functions of this System things, I've looked all over the net and havent' been able to find it.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  10. #10
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >> how would u do like if u typed ls into your program and then it ran dir.

    Code:
    #include <conio.h> // for getch()
    #include <stdlib.h> // for system()
    #include <iostream> // for cout
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    	char stringz[25];
    
    	cin >> stringz;
    
    	if(strcmp(stringz, "ls") == 0)	// strcmp return 0 if the pairs match
    	{
    		system("DIR");
    	}
    
    	getch();
        return 0;
    }
    >> hey where could I find all the functions of this System things
    http://www.computerhope.com/msdos.htm
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  11. #11
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    oh so you type any of those inside of system and it works cool thanks.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  12. #12
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Oh I tried it, that's is so freaking cool, thanks I didn't know that.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  13. #13
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >> Oh I tried it, that's is so freaking cool, thanks I didn't know that.
    What is?
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  14. #14
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Please ... Could you update me

    Could you please write the last program that you got with the last problems that you got so fare.


    thanx
    C++
    The best

  15. #15
    Registered User unknownUser's Avatar
    Join Date
    Apr 2002
    Posts
    14

    thank you

    thank you thats awesome I learn sumthing every day.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. minix system call pls help for project
    By porvas in forum Linux Programming
    Replies: 2
    Last Post: 06-14-2009, 03:40 AM
  2. Assembly example
    By Lynux-Penguin in forum C Programming
    Replies: 6
    Last Post: 04-24-2002, 08:45 PM
  3. Help needed with external call, WinExec() and timer.
    By algorithm in forum Windows Programming
    Replies: 9
    Last Post: 11-07-2001, 09:35 AM
  4. Pls help me to do this project in C I need source code
    By sureshmenon74 in forum C Programming
    Replies: 4
    Last Post: 10-04-2001, 07:57 AM
  5. call by reference and a call by value
    By IceCold in forum C Programming
    Replies: 4
    Last Post: 09-08-2001, 06:06 PM

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