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: piping in stdin

View File

@ -1,30 +1,54 @@
// Generate HTTML document form a Go source file.
package main
import (
"os"
"os/exec"
"io/ioutil"
"fmt"
)
// Just be sure to blow up on non-nil errors.
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
var err error
func markdown(path, source string) string {
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.
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage: tool/generate input.go > output.html")
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");
check(err)
pygmentizePath, err := exec.LookPath("pygmentize")
check(err)
fmt.Println(markdownPath, pygmentizePath)
fmt.Print(markdown(markdownPath, "## wat"))
// pygmentizePath, err := exec.LookPath("pygmentize")
// check(err)
//
}