summaryrefslogtreecommitdiffstats
path: root/hyper/process/main.go
blob: 297be2cfcf3089da7d892c25c9c0b454d89322b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main

import "fmt"
import "os"


func reader(file *os.File) {
  var b []byte = make([]byte, 1024)
  var err os.Error = nil
  for err == nil {
    var n int
    n, err = file.Read(b)
    fmt.Printf("data: %d, %s\n", n, b)
  }
}

func main() {
  var name = "/usr/bin/bc"
  var argv = []string{ "bc" }
  var envv = []string{ "FOO=23" }
  //var chroot = false
  var dir = "/var/empty"
  var files [3][2]*os.File
  var err os.Error
 
  for i, _ := range files {
    files[i][0], files[i][1], err = os.Pipe()
    err = err
  }

  var attr = &os.ProcAttr{
    Dir: dir,
    Env: envv,
    Files: []*os.File{ /*files[0][0] */ os.Stdin, files[1][1], files[2][1]},
  }

  var p *os.Process

  p, err = os.StartProcess(name, argv, attr)

  for _, file := range attr.Files {
    file.Close()
  }

  p=p

  go reader(files[1][0])
  reader(files[2][0])

  fmt.Printf("hello, world\n")

}