The System () function call is in C and C++, but I can't seem to find out just
exactly what it can do. I use "C++ How to Program", by Deitel and Deitel, but it's silent on the application of System(). Any help would be appreciated.
Thanks.

PS:
For example, I stumbled on this application:
system ("pause") // causes program to pause before a return to keep interactive text on the display screen.

Dani AI

Generated

As pointed out and as asked, authoritative descriptions live in the language and platform documentation. The C/C++ view of the routine and its standard-level guarantees are summarized on cppreference: std::system / system. Platform man pages and vendor docs give the exact behavior you’ll observe on POSIX or Windows (examples below).

Important behavior notes often missing from short forum answers: when the argument is non-null the call is passed to the host command interpreter and the returned value is implementation-defined. On POSIX systems the call typically runs the shell (sh -c) and returns the wait(2) status; when the argument is NULL the function reports whether a command processor is available. Interpreting exit information correctly requires the usual POSIX macros (WIFEXITED, WEXITSTATUS). See the Linux man page for details: man system(3).

Portability and safety: do not rely on specific shell commands if you want cross-platform code. Never pass untrusted strings to the shell — that creates command-injection risk. If you need output capture, use popen/pclose; if you need robust, thread-safe process creation and finer control, use posix_spawn or fork+exec on Unix-like systems, and CreateProcess or the spawn family on Windows. Useful platform docs: popen(3), posix_spawn(3), and Microsoft’s system/CreateProcess references (search Microsoft Docs for the latest CreateProcess guidance).

Practical guidance: treat system()/std::system as a convenience for quick scripts, debugging and one-off tasks, not as a building-block for production logic that requires portability, security, or precise error handling. Follow the linked docs for correct return-value handling and platform-specific caveats.

Recommended Answers

All 2 Replies

With system() you can access any old DOS command
(if you are using Linux, any old Unix command).

#include <stdlib.h>
...
system("CLS"); // the much debased clear screen
system("PAUSE"); // wait, the hard way
system("DIR"); // list the directory
... and so on!

Not recommended if you want to have portable code!!!!

vegaseat,
Thanks for your datapoint! It sheds much light on the subject to an old :D 'dos' user. Also, can you tell me where this data is documented?
Thanks again, and have a great and safe holiday season.
CPLUSPLUS
*******

With system() you can access any old DOS command
(if you are using Linux, any old Unix command).

#include <stdlib.h>
...
system("CLS"); // the much debased clear screen
system("PAUSE"); // wait, the hard way
system("DIR"); // list the directory
... and so on!

Not recommended if you want to have portable code!!!!

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.