How to implement a safer System() ?

Dec 4, 2014 at 5:50pm
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?
Dec 4, 2014 at 6:21pm
You'd have to have written code to make stack smashing or heap overflows difficult if you use the system call.
Dec 4, 2014 at 8:25pm
Thing is I'd prefer not to use system at all. I'm wondering if there is any other way to call outside programs?
Dec 4, 2014 at 9:24pm
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.
Dec 4, 2014 at 9:41pm
@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.
Dec 4, 2014 at 9:47pm
Something like that:
http://ideone.com/Mw1Nsk
Here is list of predefined macro: http://sourceforge.net/p/predef/wiki/OperatingSystems/
Dec 4, 2014 at 11:13pm
Cheers buddy, will look into it.
Topic archived. No new replies allowed.