-
System();
I'm starting this post soo people can write all the system(); codes they know.
i already know :
system("pause"); -- holds program
system("cls"); -- cleans screen
system("start") -- opens a msdos window
i know i could just open cmdline and type help but some comands in held dont work on system(); code (like exit comand)
soo people please type here any system codes know.
-
don't use system().
for a list, open your start menu, click run, type "cmd" and type "help". anything you can type on the command line can be put into system().
but don't use system(). It opens your program up to potential security flaws and makes your code non-portable... for example, try using the following code:
Code:
#include<cstdlib>
int main()
{
system("clear");
system("cal");
return 0;
}
on my system, it prints:
Code:
August 2005
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
jshao@MCP ~/Programming/C++ $
what does it do on yours?
-
-
I believe sytem is OS specific.
ie, the strings you pass are actually commands you give to the OS and obviously differ from OS to OS.
-
the system() command is standard, however what you pass to it is not. like arjunajay just said, the string (char*, actually) that you pass into system() is just basically passed on to the Operating System. when you write system("cls");, it's essentially the same as writing cls and hitting enter at the command prompt.
what I meant by my example is that there is no "list" of commands. it differs from system to system. What you can use depends on what's in your path enviroment variable. if you want a complete list on windows, type echo %PATH% and press enter. it should list a few directories. now you can type dir <pathname> (if there's a recursive version of this, use it) for each pathname listed by the first step. everything in that list can be used in the system() command. for example, I set up my windows box so that I could call GCC from the command line, so I could write system("g++ test.cpp -Wall -W -ansi -pedantic -o test.exe"); and it would work. it would not work on your system.
my point was that I'm using linux right now, and the commands I used above clears the screen and print a text calandar for this month to the screen, then exit. In windows, nothing should happen. you might get errors on the console, but that's about it.
basically here's my point: DON'T USE SYSTEM().