try out os::exec and pipe
This commit is contained in:
parent
5ac69ba7e2
commit
43a6d458a5
35
backend/cmd/proctest/main.ha
Normal file
35
backend/cmd/proctest/main.ha
Normal file
|
@ -0,0 +1,35 @@
|
|||
use fmt;
|
||||
use io;
|
||||
use os::exec;
|
||||
use os;
|
||||
use strings;
|
||||
|
||||
export fn main() void = {
|
||||
let cmd = exec::cmd("./run.sh")!;
|
||||
|
||||
let stdout_pipe = exec::pipe();
|
||||
exec::addfile(&cmd, os::stdout_file, stdout_pipe.1);
|
||||
|
||||
let stderr_pipe = exec::pipe();
|
||||
exec::addfile(&cmd, os::stderr_file, stderr_pipe.1);
|
||||
|
||||
let proc = exec::start(&cmd)!;
|
||||
io::close(stdout_pipe.1)!;
|
||||
io::close(stderr_pipe.1)!;
|
||||
|
||||
let stdout_data = io::drain(stdout_pipe.0)!;
|
||||
io::close(stdout_pipe.0)!;
|
||||
|
||||
let stderr_data = io::drain(stderr_pipe.0)!;
|
||||
io::close(stderr_pipe.0)!;
|
||||
|
||||
let status = exec::wait(&proc)!;
|
||||
let s = exec::exit(&status) as int;
|
||||
fmt::printfln("status: {}", s)!;
|
||||
|
||||
let out = strings::fromutf8(stdout_data) as str;
|
||||
fmt::printfln("stdout:\n{}", out)!;
|
||||
|
||||
let out = strings::fromutf8(stderr_data) as str;
|
||||
fmt::printfln("stderr:\n{}", out)!;
|
||||
};
|
9
backend/run.sh
Executable file
9
backend/run.sh
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "first line"
|
||||
echo "error 1" >&2
|
||||
echo "second line"
|
||||
echo "error 2" >&2
|
||||
echo "third line"
|
||||
|
||||
exit 17
|
Loading…
Reference in a new issue