v / examples / process / command.v
34 lines · 29 sloc · 579 bytes · 017ace6ea7402430a992aa0820d5e472ebca74c7
Raw
1module main
2
3import os
4
5// basic example which shows how to use the Command function
6
7fn exec(path string) string {
8 mut out := ''
9 mut line := ''
10 mut cmd := os.Command{
11 path: path
12 }
13 cmd.start() or { panic(err) }
14
15 for {
16 line = cmd.read_line()
17 println(line)
18 out += line
19 if cmd.eof {
20 return out
21 }
22 }
23 return out
24}
25
26fn main() {
27 mut out := ''
28 exec("bash -c 'find /tmp/'")
29 out = exec('echo to stdout')
30 out = exec('echo to stderr 1>&2')
31 println("'${out}'")
32 // THIS DOES NOT WORK, is error, it goes to stderror of the command I run
33 assert out == 'to stderr'
34}
35