Skip to content

Commit f78334a

Browse files
committed
---
yaml --- r: 3993 b: refs/heads/master c: b022dde h: refs/heads/master i: 3991: 593a42c v: v3
1 parent 4266e87 commit f78334a

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: fb9a117743636ac41cf494dde6198c955270a67e
2+
refs/heads/master: b022dde5876b61f646e9e44f3d9db91926d91615

trunk/src/lib/run_program.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import str::sbuf;
33
import vec::vbuf;
44

5+
export program;
6+
export run_program;
7+
export start_program;
8+
export program_output;
9+
510
native "rust" mod rustrt {
611
fn rust_run_program(vbuf argv, int in_fd, int out_fd, int err_fd) -> int;
712
}
@@ -13,12 +18,18 @@ fn arg_vec(str prog, vec[str] args) -> vec[sbuf] {
1318
ret argptrs;
1419
}
1520

16-
fn run_program(str prog, vec[str] args) -> int {
21+
fn spawn_process(str prog, vec[str] args,
22+
int in_fd, int out_fd, int err_fd) -> int {
1723
// Note: we have to hold on to this vector reference while we hold a
1824
// pointer to its buffer
1925
auto argv = arg_vec(prog, args);
20-
auto pid = rustrt::rust_run_program(vec::buf(argv), 0, 0, 0);
21-
ret os::waitpid(pid);
26+
auto pid = rustrt::rust_run_program(vec::buf(argv),
27+
in_fd, out_fd, err_fd);
28+
ret pid;
29+
}
30+
31+
fn run_program(str prog, vec[str] args) -> int {
32+
ret os::waitpid(spawn_process(prog, args, 0, 0, 0));
2233
}
2334

2435
type program =
@@ -33,12 +44,8 @@ type program =
3344
fn start_program(str prog, vec[str] args) -> @program {
3445
auto pipe_input = os::pipe();
3546
auto pipe_output = os::pipe();
36-
// Note: we have to hold on to this vector reference while we hold a
37-
// pointer to its buffer
38-
auto argv = arg_vec(prog, args);
39-
auto pid =
40-
rustrt::rust_run_program(vec::buf(argv),
41-
pipe_input._0, pipe_output._1, 0);
47+
auto pid = spawn_process(prog, args, pipe_input._0, pipe_output._1, 0);
48+
4249
if (pid == -1) { fail; }
4350
os::libc::close(pipe_input._0);
4451
os::libc::close(pipe_output._1);

0 commit comments

Comments
 (0)