1 | module main |
2 | |
3 | import os |
4 | |
5 | // basic example which shows how to use the Command function |
6 | |
7 | fn 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 | |
26 | fn 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 | } |