[erlang-questions] Executing external commands
Mon Feb 12 04:58:36 CET 2007
following works on Linux ...
$ uname -a
Linux delora 2.6.17-10-386 #2 Fri Oct 13 18:41:40 UTC 2006 i686 GNU/Linux
Erlang (BEAM) emulator version 5.5.3 [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.5.3 (abort with ^G)
1> os:cmd("/bin/ls fubar; echo $?").
"/bin/ls: fubar: No such file or directory\n2\n"
2> os:cmd("/bin/ls foo; echo $?").
You can then parse out the return value from the echo. There are
probably other ways to get the result you are looking for.
I think this discussion came up a few months ago. The above is the result
of the particular shell called.
On Sun, Feb 11, 2007 at 09:48:10PM -0200, Fernando Ipar wrote:
> Hi all.
> I'm looking for a way to run external commands in erlang and get it's
> exit code back to erlang.
> As far as I understand, os:cmd(Command) only returns the output of
> running the program.
> Is there a way to get the exit code from the command, or do I have to
> implement an external program to run these commands and communicate
> back and forth with erlang through a port?
> What I'm looking for is something like:
> case ExitCode of
> 0 ->
> _ ->
> Thanks and regards,
> erlang-questions mailing list
Portland, Oregon, USA
+1 503 283 5284
More information about the erlang-questions