Example #1
0
func start_server(host client.Anchor, id int) bool {

	debug("[%s] starting server ", host.ServerID())
	job := host.Walk([]string{"iperf", "server"})
	proc, _ := job.MakeProc(client.Cmd{
		Path:  "/bin/sh",
		Dir:   "/tmp",
		Args:  []string{"-c", "iperf -s"},
		Scrub: true,
	})

	phase := proc.Peek().Phase
	debug("[%s] iperf server "+phase, host.ServerID())
	go func() {
		debug("TEST OUTPUT START:")
		for {
			if b, err := ioutil.ReadAll(proc.Stdout()); err == nil {
				debug("out[%s]", string(b))
			}
		}
	}()

	io.Copy(proc.Stdin(), bytes.NewBufferString("\r\n"))

	proc.Stdin().Close() // Must close the standard input of the shell process.
	return false
}
Example #2
0
func runShellStdin(host client.Anchor, cmd, stdin string) (string, error) {
	defer func() {
		if recover() != nil {
			abort("connection to host lost")
		}
	}()
	job := host.Walk([]string{"shelljob", strconv.Itoa(rand.Int())})
	proc, _ := job.MakeProc(client.Cmd{
		Path:  "/bin/sh",
		Dir:   "/tmp",
		Args:  []string{"-c", cmd},
		Scrub: true,
	})
	go func() {
		io.Copy(proc.Stdin(), bytes.NewBufferString(stdin))
		proc.Stdin().Close() // Must close the standard input of the shell process.
	}()
	proc.Stderr().Close() // Close to indicate discarding standard error
	var buf bytes.Buffer
	io.Copy(&buf, proc.Stdout())
	stat, _ := proc.Wait()
	return buf.String(), stat.Exit
}