[erlang-questions] os:cmd/1 with return code

BJörn Lindqvist bjourne@REDACTED
Sat Oct 18 23:38:14 CEST 2008

2008/10/18 Richard Carlsson <richardc@REDACTED>:
> BJörn Lindqvist wrote:
>> 2008/10/18 Tim Fletcher <twoggle@REDACTED>:
>>>> I've been trying to implement and os:cmd/1 variant that also returns
>>>> the status code of the executed command. But it proved to be
>>>> exceedingly difficult.
>>> There's an example of that in eunit:
>>>  http://svn.process-one.net/contribs/trunk/eunit/src/eunit_lib.erl
>> That function does not run the command in a shell. So, for example,
>> eunit_lib:command("exit 123") will not work.
> _Should_ it run in a shell? I didn't find it obvious what a command
> that "runs an operating system command" ought to do. If someone can
> lay down the law here, I'd be grateful. I mean, it can obviously be
> handy to be able to execute any shell command directly, but I guessed
> that it might also be _not_ what one always wants. And of course, the
> code must check then which platform it is on, so it can run the right
> shell (for some definition of right).

Yes it should. os:cmd/1 mimics the system() C library function and the
man page says that it "Executes Command in a command shell."
Unfortunately since os:cmd/1 doesn't actually use the system() call,
its semantics are off in corner cases.

mvh Björn

More information about the erlang-questions mailing list