Created
February 15, 2015 19:26
-
-
Save ericchiang/4116737e44b012ae20bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"net/http" | |
"os" | |
"os/exec" | |
"golang.org/x/net/websocket" | |
) | |
func main() { | |
addr := flag.String("addr", ":8080", "Specify the address to listen on") | |
flag.Parse() | |
args := flag.Args() | |
if len(args) == 0 { | |
fmt.Fprintf(os.Stderr, "Must specify command to run\n") | |
os.Exit(2) | |
} | |
h := func(ws *websocket.Conn) { | |
cmd := exec.Command(args[0], args[1:]...) | |
cmd.Stdout = ws | |
cmd.Stderr = ws | |
cmd.Stdin = ws | |
cmd.Run() | |
} | |
http.ListenAndServe(*addr, websocket.Handler(h)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment