[erlang-questions] Executing external commands

Fernando Ipar <>
Tue Feb 13 13:20:45 CET 2007


I don't know how I thought 7 was a 'normal' exit code, I have no excuse :)

Thanks for the observation, and the suggestion!

So far, I think I'm sticking with the port based implementation 
suggested by Richard, since I can save
reversing the list if all I need is the Exit Code and not the Output, 
plus it should run on windows, should
I ever want to do that too.

Regards,
Fernando.

Per Hedeland wrote:
>> 4> ext:check("lsss /bin").
>> {"7","sh: line 1: lsss: command not found\n127\n"}
>>     
>   ^^^                                       ^^^
>
> Oops!:-) If you want to stick with regexp, a more proper incantation
> might be:
>
>     {match, Start, Length} = regexp:match(Output,"\n[0-9]+\n$"),
>     {string:substr(Output,Start+1,Length-2), Output}.
>
> However I think this might be preferrable:
>
>     Code = hd(lists:reverse(string:tokens(Output, "\n")))
>
> --Per Hedeland
>   




More information about the erlang-questions mailing list