How to implement a safer System() ?

So I've read, over multiple forums the evil in which the System() keyword is. I have no objection to it, I understand why it is hated, but what if I need it?

I want to make a compilation server:

I would send a source file over to the server, the server would compile it, then send me the executable.

The only way ( That I know of at least ) to use system calls is by using the System() keyword:

system("g++ " + filename + "-o " + output)


Is there any platform independent solutions?
You'd have to have written code to make stack smashing or heap overflows difficult if you use the system call.
Thing is I'd prefer not to use system at all. I'm wondering if there is any other way to call outside programs?
Any call to OS would not be platform independent as different platforms have different capabilities.

You can use OS API to do stuff you need. In your case you may use ShellExecute/CreateProcess in Windows or spawn/exec in Linux. If you want it to compile on any platform, wrap platform dependent parts in conditional compilation statement.
@MiiNiPaa

Yes, I figured as much. Wasn't sure what functions to call.


How exactly would one:

wrap platform dependent parts in conditional compilation statement.


? I've never done something like that.
Something like that:
http://ideone.com/Mw1Nsk
Here is list of predefined macro: http://sourceforge.net/p/predef/wiki/OperatingSystems/
Cheers buddy, will look into it.
Topic archived. No new replies allowed.