首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

erlang调用外部程序怎么得到其退出状态

2012-12-26 
erlang调用外部程序如何得到其退出状态转载请注明,来自:http://blog.csdn.net/skyman_2001经常会有erlang

erlang调用外部程序如何得到其退出状态

转载请注明,来自:http://blog.csdn.net/skyman_2001

经常会有erlang程序调用外部程序的需求,比如调用shell命令程序,一般是用os:cmd/1,比如:

1> erlang:open_port({spawn, "erlc"}, [exit_status]).#Port<0.573>2> flush().Shell got {#Port<0.573>,{exit_status,0}}ok3> erlang:open_port({spawn, "erlc a.erl"}, [exit_status]).#Port<0.584>4> flush().                                               Shell got {#Port<0.584>,{data,"a.erl:none: no such file or directory\n"}}Shell got {#Port<0.584>,{exit_status,1}}ok

关于上面的exit_status:

When the external process connected to the port exits, a message of the form {Port,{exit_status,Status}} is sent to the connected process, where Status is the exit status of the external process. If the program aborts, on Unix the same convention is used as the shells do (i.e., 128+signal).


热点排行