[erlang-questions] Call erlang:port_info/1 from shell

Allen Kim allen.kim@REDACTED
Wed Jun 22 16:34:50 CEST 2011


I believe c:pid/3 is given to you for convenience of debugging.
I don't think there is one that converts list(string) to port, and I also think we do not convert string to port in code.

since it is shell environment you want to run on,  I don't think performance really matters.
If so, you can use a simple function like this.

PortInfo = fun(Num) ->
   [MyPort] =lists:filter(fun(Port) -> {id,PortNum} = erlang:port_info(Port,id), PortNum==Num end, erlang:ports()),
   erlang:port_info(MyPort)
end.

PortInfo(267).

Allen

From: "Andy W. Song" <wsongcn@REDACTED<mailto:wsongcn@REDACTED>>
Date: Wed, 22 Jun 2011 09:07:18 -0500
To: Allen Kim <allen.kim@REDACTED<mailto:allen.kim@REDACTED>>
Subject: Re: [erlang-questions] Call erlang:port_info/1 from shell

This is not convenient. I can use pid(0,22222,0) to get a pid from shell. I suppose there should be a similar way for ports. If have thousands of ports, which I do, and I just want to examine one of them from shell, I can't walk through them.

2011/6/22 Allen Kim <allen.kim@REDACTED<mailto:allen.kim@REDACTED>>
[ erlang:port_info(Port) || Port <- erlang:ports()].

You can also use lists:foreach instead.

From: "Andy W. Song" <wsongcn@REDACTED<mailto:wsongcn@REDACTED>>
Date: Wed, 22 Jun 2011 08:49:30 -0500
To: erlang-questions <erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>>
Subject: [erlang-questions] Call erlang:port_info/1 from shell

Hi,

If I run erlang:ports() from shell, it shows

[#Port<0.1>,#Port<0.113>,#Port<0.118>,#Port<0.125>,
 #Port<0.513>,#Port<0.526>,#Port<0.201852>,#Port<0.202767>,
 #Port<0.202768>,#Port<0.202769>,#Port<0.202770>,
 #Port<0.202771>,#Port<0.202772>,#Port<0.202773>,
 #Port<0.202774>,#Port<0.202775>,#Port<0.202776>,
 #Port<0.202777>,#Port<0.202778>,#Port<0.202779>,
 #Port<0.202780>,#Port<0.202781>,#Port<0.202782>,
 #Port<0.202783>,#Port<0.202784>,#Port<0.202785>,
 #Port<0.202786>,#Port<0.202787>,#Port<0.202788>|...]

Now I want to call erlang:port_info/1, but I don't know how to build the Port() parameter from say #Port<0.513>. Can anybody help? And BTW, where should I look for the document about this kind of thing?

Thanks
Andy

--
---------------------------------------------------------------
有志者,事竟成,破釜沉舟,百二秦关终属楚
苦心人,天不负,卧薪尝胆,三千越甲可吞吴




--
---------------------------------------------------------------
有志者,事竟成,破釜沉舟,百二秦关终属楚
苦心人,天不负,卧薪尝胆,三千越甲可吞吴

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110622/2d90bcdc/attachment.htm>


More information about the erlang-questions mailing list