Still a little problem with os_cmd("")

Nico Weling nico.weling@REDACTED
Thu Oct 11 08:41:56 CEST 2001


Hi Ulf, and other Erlang-gurus,

for os_cmd("sendfax -l /dev/ms0 0172234234 fax.g3") it works fine. But now I've seen that for this one:

	1> gmc_util:os_cmd("mgetty /dev/ms1").
	[]

the command is executed directly, and commes back with '[]' but the process is still running and not finished. 

if I execute this:

	sh -c 'mgetty /dev/ms1' 2>&1

from the command line the 'prompt' comes only back if I stop (kill) the process.

Does anybody know why?

Regards,

Nico.


======================================================
os_cmd(Cmd) ->
    Command = binary_to_list(
                list_to_binary(["sh -c '", Cmd,
                                "' 2>&1"])),
    Port = open_port({spawn, Command}, [stream, eof]),
    get_data(Port, []).

get_data(Port, Sofar) ->
    receive
        {Port, {data, Bytes}} ->
            get_data(Port, Sofar ++ Bytes);
        {Port, eof} ->
            Port ! {self(), close},
            receive
                {Port, closed} ->
                    true
            end,
            receive
                {'EXIT', Port, _} ->
                    ok
            after 1 ->
                    ok
            end,
            Sofar;
        {'EXIT', Port, _} ->
            Sofar
    after 120000 ->
            exit(timeout)
    end.



More information about the erlang-questions mailing list