[erlang-questions] Run external program with arguments

Torbjorn Tornkvist tobbe@REDACTED
Wed Nov 14 16:37:07 CET 2007


Bob Ippolito wrote:
> The easiest way is to perform shell quoting over the command you
> want... take a look at mochiweb_util:cmd_port/2.
> 
> http://mochiweb.googlecode.com/svn/trunk/src/mochiweb_util.erl

Hm...that join function. Couldn't it be written like:

%%-----------------------------------------------------------------------------
%% @spec implode(Str::string(), Sep::string()) -> string()
%%
%% @doc  split text at first occurence of Char (Char is not include in
Before
%%       or After parts)
%%
%%  Example:  implode(["a","b","c"], ".") => "a.b.c"
%%
%%
@end------------------------------------------------------------------------
implode(Data, Seperator) when is_list(Data) andalso is_list(Seperator) ->
    lists:foldr(fun(X,[]) -> X; (X,Acc) -> X++Seperator++Acc end, "", Data).


Cheers, Tobbe

> 
> -bob
> 
> On 11/14/07, Alexander Zhukov <azhukov@REDACTED> wrote:
>> Hi!
>>
>> Is there a way to run an external program from Erlang program with
>> arguments?
>>
>> I like to be able to write something like this:
>>
>> Port = open_port({spawn, Ext_prog_name}, [stream, {args, ["-c", "file", "-d"]}]),
>>
>> but so far I can't find a way to run a program with arguments.
>>
>> Yes, I know I can write a wrapper script but I do not like such an
>> approach.
>>
>> --
>> Alexander Zhukov
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>




More information about the erlang-questions mailing list