I just wanted to start a list of system(" ") funtions. I'll write all of the ones I know and if you know any more please post them. Thanks for contributing!!! ^_^

system("pause"); - This displays "Press any key to continue..." and waits for a key to be hit to resume.

system("cls"); - This clears everything prviously input into the output window.

system("title WINDOW"); - This displays whetever comes after title, this would display "WINDOW" at the name of the window.

system("color 08"); - This changes the color of the background and the text in the output window. The first number controls the background color and the second controls the text color. For this:
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White

If you know any more pleaase post them!!! Thanks!!! ^_^

You realize these are just DOS commands? Oh and btw, none of your commands work on *my* computer, I wonder why that is.

list of of the executables in c:\windows directory, all of its sub directories and everywhere else on your computer's hard drive. That's how many things can be run with the system function. There are litterally thousands of them, so attempting to post them here is pointless.

There are litterally thousands of them, so attempting to post them here is pointless.

Well way to shoot me down off of my pedastal, thanks guys. >.<

Don't feel too bad. People post system() stuff all the time.

Other than using "cls" or "clear" in a homework assignment, there are always better ways to do things than by using system().

One of the main problems with it is it is a security hole in your program --even if you are not writing secure systems software.

Another is the overhead. Just to clear the screen or do some other simple thing it takes a relatively large amount of time and resources.

Thanks Duoas, but system() still seems to be a very strong function to me. It just seems a little to useful for me to give up just yet. But I'll try to avoid using it as I advance my programming. ^_^

Almost all the functions in the C library are useful in their domain (all except gets()!).

Use system() when you need to. There is nothing wrong with it.

However, how often do you need to execute shell commands from your program? The usefulness is pretty rare. The thing people get upset about is that system() gets used for all sorts of stuff it shouldn't be.

For example, it is cool that you can set the console window's title from the cmd prompt, but that is a Win32 thing. Instead of spawning a new shell and sending it a command which will likely fail on any system except Win 98+, just use the SetConsoleTitle() function, and let compilation fail if the program won't work on the target system. Make sense?

That's all I meant.

system("ftype")
system("tree")
system("dir")
are good ones but yet pointless :/

commented: Thanks for the help!!! ^_^ +1

Littering your code with system() is little better than writing batch files.

Plus every call to system() involves running at least one additional process, possibly more. Starting a process is expensive, so it's best avoided.

And system() is very easy to subvert into doing something other than what you intended.

Littering your code with system() is little better than writing batch files.

Plus every call to system() involves running at least one additional process, possibly more. Starting a process is expensive, so it's best avoided.

And system() is very easy to subvert into doing something other than what you intended.

not necessarily if executed right the system() tag is very good but still best to avoid. And no it will not create another process unless you tell it too.

Exactly how do you tell system() not to create another process?

If command is NULL and the command interpreter is found, returns a nonzero value. If the command interpreter is not found, returns 0 and sets errno to ENOENT. If command is not NULL, system returns the value that is returned by the command interpreter. It returns the value 0 only if the command interpreter returns the value 0. A return value of – 1 indicates an error, and errno is set to one of the following values:

http://msdn2.microsoft.com/en-us/library/277bwbdz(VS.80).aspx

Sure there are some special cases where a command interpreter isn't created, but then nothing else happens either.

And system() is very easy to subvert into doing something other than what you intended.

not necessarily if executed right the system() tag is very good but still best to avoid.

How exactly are you to guarantee that the user doesn't replace an external program from your code? The system() function does exactly what it is supposed to: execute an external program. Anytime you do that it is a security hole.

And no it will not create another process unless you tell it too.

Grumble... You are aware, perhaps, that the whole point of the system() function is to create another process?

It executes another copy of your system shell, which in turn may execute yet another process (or processes)...

How exactly are you to guarantee that the user doesn't replace an external program from your code? The system() function does exactly what it is supposed to: execute an external program. Anytime you do that it is a security hole.


Grumble... You are aware, perhaps, that the whole point of the system() function is to create another process?

It executes another copy of your system shell, which in turn may execute yet another process (or processes)...

For example if I do system("dir"); that will print the current directory to the screen. This will NOT start a new process in the processes tab in taskman. If you use system() to call a file not only would this be stupid but this WOULD start another process. For example if I do system("start bleh.bat"); that will start the process bleh.bat Not every thing you use system for starts another process.

commented: N/A +0

> This will NOT start a new process in the processes tab in taskman.
Of course it does, but if you try it on a small directory the process doesn't last long enough for it to show up.
Try it with something which takes a while, then you'll see it.
Say system("dir /s c:\\windows"); > Not every thing you use system for starts another process.
Starting a process is in the spec. All you're citing is short-lived programs which don't last long enough to see them in your taskman.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.