设为首页 加入收藏

TOP

Golang lsof server
2014-11-24 00:04:11 来源: 作者: 【 】 浏览:13
Tags:Golang lsof server

01 package main
02
03 import (
04 "net/http"
05 "fmt"
06 "os/exec"
07 "flag"
08 )
09
10 func main(){
11 http.HandleFunc("/", readHandle)
12 port := flag.Int("port", 2012, "Listen Port")
13 flag.Parse()
14 http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
15
16 }
17
18
19 func readHandle(w http.ResponseWriter, r *http.Request){
20 /* Command */
21 lsof := exec.Command("lsof", r.FormValue("path"))
22 wc := exec.Command("wc", "-l")
23 /* Pipe */
24 lsofOut,_ := lsof.StdoutPipe()
25 /* Command Start */
26 lsof.Start()
27 /* Stdin */
28 wc.Stdin = lsofOut
29 out,_ := wc.Output()
30
31 fmt.Fprintf(w, "%v", r.FormValue("path"))
32 fmt.Fprintf(w, "%s", out)
33 fmt.Fprintf(w, "%s", r.URL.Path[1:])
34 }

作者:ioser
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言实现《大话设计模式》中的观.. 下一篇字符串分割函数strtok

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: