processes bitches

This commit is contained in:
Mark McGranaghan 2012-09-23 19:36:24 -07:00
parent 2a5d37fad3
commit 7d8b99197f
2 changed files with 31 additions and 6 deletions

View File

@ -16,3 +16,4 @@ func main() {
} }
// todo: full command lines with bash // todo: full command lines with bash
// todo: piping in stdin

View File

@ -1,30 +1,54 @@
// Generate HTTML document form a Go source file.
package main package main
import ( import (
"os" "os"
"os/exec" "os/exec"
"io/ioutil"
"fmt" "fmt"
) )
// Just be sure to blow up on non-nil errors.
func check(err error) { func check(err error) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
} }
func main() { func markdown(path, source string) string {
var err error cmd := exec.Command(path)
in, err := cmd.StdinPipe()
check(err)
out, err := cmd.StdoutPipe()
check(err)
err = cmd.Start()
check(err)
in.Write([]byte(source))
check(err)
err = in.Close()
check(err)
bytes, err := ioutil.ReadAll(out)
check(err)
err = cmd.Wait()
check(err)
return string(bytes)
}
func main() {
// Accept exactly 1 argument - the input filename. // Accept exactly 1 argument - the input filename.
if len(os.Args) != 2 { if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage: tool/generate input.go > output.html") fmt.Fprintln(os.Stderr, "Usage: tool/generate input.go > output.html")
os.Exit(1) os.Exit(1)
} }
// Ensure that we have `markdown` and `pygmentize` binaries. // Ensure that we have `markdown` and `pygmentize`,
// binaries, remember their paths.
markdownPath, err := exec.LookPath("markdown"); markdownPath, err := exec.LookPath("markdown");
check(err) check(err)
pygmentizePath, err := exec.LookPath("pygmentize") fmt.Print(markdown(markdownPath, "## wat"))
check(err) // pygmentizePath, err := exec.LookPath("pygmentize")
fmt.Println(markdownPath, pygmentizePath) // check(err)
//
} }