Thread: system("")

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    67

    system("")

    This is dos specific I think. Could someone list the most useful system commands and what they do?

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Any command you use normally at the command prompt/msdos prompt you can place between the brackets, but the 2 most commonly used ones are:
    Code:
    system("pause"); // Displays "Press any key to continue..."
    system("cls"); // clears the screen

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    There are loads of DOS commands....

    Books like "DOS for Dummies" by Dan Gookin are cheap and give you a good start with learning DOS

  4. #4
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    very very useful ones are COPY, etc.
    www.easydos.com/index
    all the commands there can be done through system...if i remember correctly, it can even be used to launch other programs instead of using shellExecute() like so
    Code:
    system("cd c:\whatever");
    system("someProgram.exe"); //where someProgram resides in c:\whatever
    PHP and XML
    Let's talk about SAX

  5. #5
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    yeah, ok.. But then how do you read off what that program prints out or access any of the values that program returns?

  6. #6
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    well, i know that if i call the COPY program in from system and something goes wrong it will print out the error within my program...so, yeah, my guess is as good as yours, but the program WILL execute, that's all im saying
    PHP and XML
    Let's talk about SAX

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Aran Elus
    yeah, ok.. But then how do you read off what that program prints out or access any of the values that program returns?
    You can reroute the programs output to another stream (say a file) and then read itor do whatever.....

    The return of the executed program is the return of system()

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main (){
    
    	FILE *fout = NULL;
    	char c;
    	int nRet;
    
    	fout = freopen("myfile.txt","w",stdout);//all output to file
    	nRet = system("DIR");//run your command, save result
    	freopen("CON","w",stdout);//restore stream (this closes file)
    	fout = fopen("myfile.txt","r");//open the file again
    	printf("Results of DIR command\n");
    	while((c = fgetc(fout)) != EOF)//read contents
    		putc(c,stdout);	//spit out results
    	printf("\nExited with a return of %d\n",nRet);//State result
    	fclose(fout);
    	
        return 0;
    }

  8. #8
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Or simply use popen()

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The standard c library eliminates the need for the use of the function system(). Code like this:

    Code:
    //assume name is a char *
    remove(name);
    runs much faster than this:

    Code:
    //assume temp is also a char *
    sprintf(temp, "delete %s", name);
    system(temp);
    Of course in terms of easy some prefer copying a file in one slow system() call rather than a couple of calls to various stdio functions.

  10. #10
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    The only time I use System is to use simple program that either I've written specifically for that purpose, and programs that produce no output themselves. It simply a way of telling the system what to do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with system(""); command!
    By guitarist809 in forum C++ Programming
    Replies: 3
    Last Post: 05-21-2006, 11:39 AM
  2. using string with system("") help
    By aznboi in forum C++ Programming
    Replies: 2
    Last Post: 10-12-2005, 10:45 PM
  3. System("");
    By bluehead in forum C++ Programming
    Replies: 19
    Last Post: 01-26-2002, 06:00 PM