Thanks, it works very well. <div>When I call PortInfo(868) I get:<div>[{name,"tcp_inet"},</div><div> {links,[<0.234.0>]},</div><div> {id,868},</div><div> {connected,<0.234.0>},</div><div> {input,0},</div>
<div> {output,12788}]</div><div><br></div><div>So here comes my next question: how can I find out the socket information associated to this port, such as ip and port?</div><div><br></div><div>Thanks</div><div>Andy</div><div>
<br></div><br><div class="gmail_quote">2011/6/22 Allen Kim <span dir="ltr"><<a href="mailto:allen.kim@epicadvertising.com">allen.kim@epicadvertising.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word;color:rgb(0, 0, 0);font-size:14px;font-family:Calibri, sans-serif"><div><div><div><div><div><div>I believe c:pid/3 is given to you for convenience of debugging.</div></div></div><div>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.</div>
<div><br></div><div>since it is shell environment you want to run on, I don't think performance really matters.</div><div>If so, you can use a simple function like this.</div><div><br></div><div><div>PortInfo = fun(Num) -></div>
<div> [MyPort] =lists:filter(fun(Port) -> {id,PortNum} = erlang:port_info(Port,id), PortNum==Num end, erlang:ports()), </div><div> erlang:port_info(MyPort)</div><div>end.</div></div><div><br></div><div>PortInfo(267).</div>
</div><div><br></div><div>Allen</div><div class="im"><div><br></div><div><span style="font-family:Helvetica;font-size:medium"><div style="word-wrap:break-word"><span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium"><div style="word-wrap:break-word">
<span style="font-family:Calibri;font-size:15px"><span style="font-weight:bold">From: </span> "Andy W. Song" <<a href="mailto:wsongcn@gmail.com" target="_blank">wsongcn@gmail.com</a>></span></div></span></div>
</span></div></div></div></div><span><div style="font-family:Calibri;font-size:11pt;text-align:left;color:black;border-bottom:medium none;border-left:medium none;padding-bottom:0in;padding-left:0in;padding-right:0in;border-top:#b5c4df 1pt solid;border-right:medium none;padding-top:3pt">
<span style="font-weight:bold">Date: </span> Wed, 22 Jun 2011 09:07:18 -0500<br><span style="font-weight:bold">To: </span> Allen Kim <<a href="mailto:allen.kim@epicadvertising.com" target="_blank">allen.kim@epicadvertising.com</a>><br>
<span style="font-weight:bold">Subject: </span> Re: [erlang-questions] Call erlang:port_info/1 from shell<br></div><div><div></div><div class="h5"><div><br></div>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.<br>
<br><div class="gmail_quote">2011/6/22 Allen Kim <span dir="ltr"><<a href="mailto:allen.kim@epicadvertising.com" target="_blank">allen.kim@epicadvertising.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;color:rgb(0, 0, 0);font-size:14px;font-family:Calibri, sans-serif"><div><div><div>[ erlang:port_info(Port) || Port <- erlang:ports()].</div><div><br></div><div>You can also use lists:foreach instead.</div>
<div><div style="word-wrap:break-word;font-family:Helvetica;font-size:medium"><font face="Calibri, sans-serif"><font face="Helvetica"><br></font></font></div></div></div></div><span><div style="font-family:Calibri;font-size:11pt;text-align:left;color:black;border-bottom:medium none;border-left:medium none;padding-bottom:0in;padding-left:0in;padding-right:0in;border-top:#b5c4df 1pt solid;border-right:medium none;padding-top:3pt">
<span style="font-weight:bold">From: </span> "Andy W. Song" <<a href="mailto:wsongcn@gmail.com" target="_blank">wsongcn@gmail.com</a>><br><span style="font-weight:bold">Date: </span> Wed, 22 Jun 2011 08:49:30 -0500<br>
<span style="font-weight:bold">To: </span> erlang-questions <<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a>><br><span style="font-weight:bold">Subject: </span> [erlang-questions] Call erlang:port_info/1 from shell<br>
</div><div><div></div><div><div><br></div>Hi, <div><br></div><div>If I run erlang:ports() from shell, it shows</div><div><div> </div><div>[#Port<0.1>,#Port<0.113>,#Port<0.118>,#Port<0.125>,</div>
<div> #Port<0.513>,#Port<0.526>,#Port<0.201852>,#Port<0.202767>,</div><div> #Port<0.202768>,#Port<0.202769>,#Port<0.202770>,</div><div> #Port<0.202771>,#Port<0.202772>,#Port<0.202773>,</div>
<div> #Port<0.202774>,#Port<0.202775>,#Port<0.202776>,</div><div> #Port<0.202777>,#Port<0.202778>,#Port<0.202779>,</div><div> #Port<0.202780>,#Port<0.202781>,#Port<0.202782>,</div>
<div> #Port<0.202783>,#Port<0.202784>,#Port<0.202785>,</div><div> #Port<0.202786>,#Port<0.202787>,#Port<0.202788>|...]</div><div><br></div><div>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?</div>
<div><br></div><div>Thanks</div><div>Andy</div><br>-- <br><div>---------------------------------------------------------------</div><div>有志者,事竟成,破釜沉舟,百二秦关终属楚</div><div>苦心人,天不负,卧薪尝胆,三千越甲可吞吴</div><br></div></div></div></span></div>
</blockquote></div><br><br clear="all"><br>-- <br><div>---------------------------------------------------------------</div><div>有志者,事竟成,破釜沉舟,百二秦关终属楚</div><div>苦心人,天不负,卧薪尝胆,三千越甲可吞吴</div><br></div></div></span></div>
</blockquote></div><br><br clear="all"><br>-- <br><div>---------------------------------------------------------------</div><div>有志者,事竟成,破釜沉舟,百二秦关终属楚</div><div>苦心人,天不负,卧薪尝胆,三千越甲可吞吴</div><br>
</div>