> wrapping CLI commands to turn them into APIs/make them programmable
CLI apps are already very programmable. How would you API-ify them even more?
system('yourapp --option1 --option2=something')CLI apps are already very programmable. How would you API-ify them even more?
system('yourapp --option1 --option2=something')Starting a subprocess via shell is could in particular be solved by a simple API of the form of:
system('yourapp', ['option1', {'option2' : 'something'}]);
in your favourite language. Handling pipes and redirects gets more complex, but I see no prima facie reason why it couldn't look like this: pipe(system('yourapp', ['option1', {'option2' : 'something'}]),
system('grep', ['n', 'i', 'foobar']),
system('somethingelse', [], null, file("/dev/null")));I agree that system() (in C and other langues that simply copied it) is a bad API. For shell escaping a command to start a process with a list of arguments would be enough, and even POSIX C has you covered there with vararg and array variants. [1]
[1] http://man7.org/linux/man-pages/man3/posix_spawn.3.html (or fork() + exec())
(personally, I think it is, and helps give structure to the sometimes too "dynamic" world that is shell scripting)