Hi everyone!

I know using "system" in c++ is not the best way to develop, however, I need to use it for some specific reason.

I have read that it is advisable using before system(NULL) to check if there is a shell available.

My question are:

When is not going to be available a shell?
Is that check really needed or removing it will not cause further problems?

The code would be as follows:

if ( system(NULL) != 0)

Any help would be apreciated,


6 Years
Discussion Span
Last Post by Ancient Dragon

>>When is not going to be available a shell?
Some embedded systems don't have a shell. I have not used all operatin gsystems so I suppose there could be a few others out there too that don't have shells. MS-Windows and *nix will always have one available.

Instead of testing system(NULL) why not simply test system(myprog)? Why bother calling system() twice when once will do.


Every time I run this program will be on a specific linux, so I understand that checking the availability of the shell would be useless.

I have taken the idea from here.



Since a shell is a user-interface to the os I suppose there may be versions of *nix which run without a shell and without human interface. I think those would be pretty rare cases.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.