Still a little problem with os_cmd("")

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Still a little problem with os_cmd("")

Nico Weling
Hi Bengt,


> If I run your os_cmd() function with something that does not return
> sufficiently fast I get an exception. Unless I am mistaken 'mgetty'
> should run continually, and therefore always generate the exception.
> Or have I missed something?

Usualy you start mgetty at an specific runlevel an respawn it after you
have received an fax. I want to start it by myself after I have see an
ringing indication for a fax at the serial port. Then I start the
os_cmd("mgetty...") and if it returns I know that the transmission of the
fax is terminated.

 
> 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"


Regards,

Nico.


Reply | Threaded
Open this post in threaded view
|

Still a little problem with os_cmd("")

Ulf Wiger-4
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