Problems with os_cmd

Nico Weling <>
Wed Oct 17 11:14:23 CEST 2001


Hi all,

I'm using the os_cmd program (thanks to Ulf) which is shown at the end of this mail. If I execute kermit with os_cmd I always get only the last two lines. If I execute kermit from the unix-shell I have the important information for filesize etc.

Why don't I get this infomation with the os_cmd programm?

Thanks in advance,

best regards/Nico.


========================================================================================

Eshell V4.9.1  (abort with ^G)
1>  gmc_util:os_cmd("kermit /etc/kermit/r520.cfg -l /dev/ms1 -r -a /home/data_receive/").
Bytes: "\r\n"
Bytes: "Closing /dev/ms1...OK\n"
"\r\nClosing /dev/ms1...OK\n"

========================================================================================

[ gmc]# sh -c 'kermit /etc/kermit/r520.cfg -l /dev/ms1 -r -a /home/data_receive/' 2>&1
 RECV hosts (binary) (901 bytes): OK (4.079 sec, 220 cps)

Closing /dev/ms1...OK

[ gmc]# 

========================================================================================



gmc_util.erl:


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}} ->
	    catch ?gmc_logger ! {log, "util ~s: Sofar: ~p~n",
				 [version(), Bytes]},
	    io:format("Bytes: ~p~n",[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 300000 -> %wait 5mins before exit
            exit(timeout)
    end.



More information about the erlang-questions mailing list