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)
system(myprog);

Any help would be apreciated,

Thanks!

>>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.

Thanks!

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.

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.