As Simon points out, Switch is the right tool for procedural conditions and is more appropriate than Piecewise . Here's the solution using Switch :
BackgroundProcess[proc_String] := Switch[$OperatingSystem, "MacOSX" | "Unix", Run["(" <> proc <> ")&"], "Windows", Run["start /b " <> proc], _, $Failed]
You can write a wrapper function to handle several operating systems.
BackgroundProcess[proc_String] := Module[{ command = Piecewise[{ {proc <> " &", $OperatingSystem == "MacOSX" || "Unix"}, {"start /b " <> proc, $OperatingSystem == "Windows"} }] }, Run[command]]
/b after start starts the process in the background without creating a new command window, and the output is printed to stdout. Then you can use this to include error messages, some input sanitation (for example, not allowing rm , etc.), if you want it, and everything should be installed.
A predefined function from Mathematica (if one exists) is likely to run along these lines. Background processes are inherently OS-dependent, so there is no real “platform-independent” way to do this. Any implementation that claims to be like that (like the os module in python) is basically a set of rules defined for every possible OS that is known to exist, so you really don't need to worry about the finer details .
source share