Still a little problem with os_cmd("")
Ulf Wiger
etxuwig@REDACTED
Thu Oct 11 15:07:48 CEST 2001
On Thu, 11 Oct 2001, Nico Weling wrote:
>> PS: Could you please mention why 'Command' is constructed by calling
>> binary_to_list( list_to_binary() )? Is it to remove escape sequences?
>
>This (3>) should also work:
>
>1> Cmd="mgetty /dev/ms1".
>"mgetty /dev/ms1"
>
>2> binary_to_list(list_to_binary(["sh -c '", Cmd,"' 2>&1"])).
>"sh -c 'mgetty /dev/ms1' 2>&1"
>
>3> "sh -c '"++ Cmd ++"' 2>&1".
>"sh -c 'mgetty /dev/ms1' 2>&1"
Actually, it's a cludgy way of ensuring that what gets passed to
the open_port() command is a flat string, and nothing else.
The open_port() function doesn't accept deep lists or, for that
matter, binaries. Meanwhile, it's convenient for the user of
os_cmd() to not have to worry about flattening Cmd. Your
example (3>) above is equivalent only if Cmd is a flat list.
binary_to_list(list_to_binary(List)) has the advantage over
lists:flatten(List) that it will exit if List contains a
non-character (e.g. an atom.) I felt that it's easier to reason
about a badarg in list_to_binary/1 than about a badarg in
open_port_prim/2.
I have no answer regarding the specific 'mgetty /dev/ms1'
problem.
/Uffe
--
Ulf Wiger tfn: +46 8 719 81 95
Senior System Architect mob: +46 70 519 81 95
Strategic Product & System Management ATM Multiservice Networks
Data Backbone & Optical Services Division Ericsson Telecom AB
More information about the erlang-questions
mailing list