using "system()" is bad ?

I am not a beginner in C++ anymore, but I am not also that good at it. but I have seen dudes and guys saying not to use the system(). Why ?
Because it is not plattform independent, I think that's all there is to it...
The system() is a standard C function. Platform independent. http://www.cplusplus.com/reference/cstdlib/system/


The question is, why should our program run some another program?

Is that other program installed in every system, where our program is run? What if the system has a different program with same name earlier on the path? We would not be running the program we expect.

Running an another program implies that whatever the other program does, is required by our program. That implies communication. Passing information back and forth. Checking whether the other program succeeds.

That is all okay, if you do it for the right reasons and properly.


The problem are the blindly copied incantations:
1
2
3
using namespace std;
i++;
system( "pause" );

What are the urgent reasons that force our innocent program to depend on program "pause" (which is not available on every system)? Could we use C++ to imitate pause? What do we achieve with pause anyway? I have seen the 'pause' to be used in a MS-DOS batch script. That use was justified. There is no excuse to start pause from a C++ program.

Blindly copied. "I have no idea what that line means, but every example has it, so I use it too." That is so wrong.


It is not bad to use system(), if you know what you are doing.
It is bad to do things without thinking and knowing.
The system() is a standard C function. Platform independent.

Yeah, the function is a standard function but the command-line-processor may want different inputs in different environments so I'm not a fan of saying that system() is portable...
"The effects of invoking a command depend on the system and library implementation, and may cause a program to behave in a non-standard manner or to terminate."
Last edited on
Topic archived. No new replies allowed.