This is dos specific I think. Could someone list the most useful system commands and what they do?
Printable View
This is dos specific I think. Could someone list the most useful system commands and what they do?
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
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
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
yeah, ok.. But then how do you read off what that program prints out or access any of the values that program returns?
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
You can reroute the programs output to another stream (say a file) and then read itor do whatever.....Quote:
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?
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;
}
Or simply use popen()
The standard c library eliminates the need for the use of the function system(). Code like this:
runs much faster than this:Code://assume name is a char *
remove(name);
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.Code://assume temp is also a char *
sprintf(temp, "delete %s", name);
system(temp);
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.