blob: 718ce96326468f27ee6dd7a59c95c285dea4bbb0 (
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
|
module main
import os
// basic example which shows how to use the Command function
fn exec(path string) string {
mut out := ''
mut line := ''
mut cmd := os.Command{
path: path
}
cmd.start() or { panic(err) }
for {
line = cmd.read_line()
println(line)
out += line
if cmd.eof {
return out
}
}
return out
}
fn main() {
mut out := ''
exec("bash -c 'find /tmp/'")
out = exec('echo to stdout')
out = exec('echo to stderr 1>&2')
println("'$out'")
// THIS DOES NOT WORK, is error, it goes to stderror of the command I run
assert out == 'to stderr'
}
|