
Joachim Breitner
-- | Like 'spawn', but returns the 'ProcessID' of the launched application spawnPID :: MonadIO m => String -> m ProcessID spawnPID x = io . forkProcess . finally nullStdin $ do uninstallSignalHandlers createSession executeFile "/bin/sh" False ["-c", x] Nothing
Generally, this is of course useful. But I bet that most commands passed to spawn are simple program names without arguments or any fancy shell-related stuff. Executing a shell here seems overkill. Not much, but still avoidable.
How about checking whether the argument x contains only alphanumerical characters and, if that is the case, executing the program directly? Such short-circuit logic is for example also used by perl’s sytem(), see perldoc -f system:
I'm not a big fan of perl's all-implicit behaviour. I'd rather rename spawn(PID) to spawnShell(PID) x = spawn(PID) "/bin/sh" ["-c", x] and make the shell invocation explicit. If such incompatible change is impossible, then make it spawn(PID) x = execute(PID) "/bin/sh" ["-c", x] or similar. Meanwhile, use exec to get rid of the shell process. :) -- Regards, Feri.