open_port

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

open_port

Dietmar Schaefer
Hi !


Is there a way to distinguish the exit status of an unix process started
by open_port ?

No matter if my process terminates because of a devide by zero or I
close it ->
Reason is always normal


handle_info({'EXIT', Port, Reason}, Port) ->
    io:format("External program exited Reason=~p Port=~p~n",
          [Reason, Port]),
    {stop, shutdown, noport};


Thanks



regards


Dietmar
Reply | Threaded
Open this post in threaded view
|

Re: open_port

Matthias Lang

If you add the "exit_status" option to the call to open_port, you get
exactly what you asked for:

   1> erlang:open_port({spawn, "/tmp/a.out"}, [exit_status]).
   #Port<0.79>
   2> flush().
   Shell got {#Port<0.79>,{exit_status,136}}
   3> erlang:open_port({spawn, "/bin/true"}, [exit_status]).        
   #Port<0.83>
   4> flush().                                              
   Shell got {#Port<0.83>,{exit_status,0}}

Matthias

--------------------

Dietmar Schaefer writes:

 > Is there a way to distinguish the exit status of an unix process started
 > by open_port ?
 >
 > No matter if my process terminates because of a devide by zero or I
 > close it ->
 > Reason is always normal
 >
 >
 > handle_info({'EXIT', Port, Reason}, Port) ->
 >     io:format("External program exited Reason=~p Port=~p~n",
 >           [Reason, Port]),
 >     {stop, shutdown, noport};