open_port vs stderr

David N. Welton <>
Wed Aug 11 17:05:04 CEST 2004


I was cruising through the Erlang sources having a look at how to make a 
better os:cmd.  Aside from the fact that it would currently be possible 
to do something like

{ExitStatus, Data} = os:cmd("....")

I was hoping to find a way to deal with stderr.  To my reading of the 
code though, that doesn't look very possible... are there any plans in 
the works to 'fix' this?  I suppose most people prefer not to have to 
deal with system command, and write code in erlang itself, or at most C, 
but sometimes it's useful to be able to interact with foreign commands 
in as controlled a manner as possible.

I envision being able to write code like:

	{Port, {data, Bytes}} ->
	    io:format("Received ~p~n", [Bytes]);
	{Port, {data_stderr, Bytes}} ->
	    io:format("StdErr Received ~p~n", [Bytes]);
	{Port, {exit_status, Status}} ->
	    io:format("Exit Status ~p~n", [Status]);
	Other ->
	    io:format("Not data ~p~n", [Other])

David N. Welton

More information about the erlang-questions mailing list