summaryrefslogtreecommitdiff
path: root/cli/ops/process.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops/process.rs')
-rw-r--r--cli/ops/process.rs37
1 files changed, 17 insertions, 20 deletions
diff --git a/cli/ops/process.rs b/cli/ops/process.rs
index 78d9313c0..384068e6a 100644
--- a/cli/ops/process.rs
+++ b/cli/ops/process.rs
@@ -33,12 +33,12 @@ fn clone_file(
})
}
-fn subprocess_stdio_map(s: &str) -> std::process::Stdio {
+fn subprocess_stdio_map(s: &str) -> Result<std::process::Stdio, OpError> {
match s {
- "inherit" => std::process::Stdio::inherit(),
- "piped" => std::process::Stdio::piped(),
- "null" => std::process::Stdio::null(),
- _ => unreachable!(),
+ "inherit" => Ok(std::process::Stdio::inherit()),
+ "piped" => Ok(std::process::Stdio::piped()),
+ "null" => Ok(std::process::Stdio::null()),
+ _ => Err(OpError::other("Invalid resource for stdio".to_string())),
}
}
@@ -86,28 +86,25 @@ fn op_run(
}
// TODO: make this work with other resources, eg. sockets
- let stdin_rid = run_args.stdin_rid;
- if stdin_rid > 0 {
- let file = clone_file(stdin_rid, &mut resource_table)?;
- c.stdin(file);
+ if run_args.stdin != "" {
+ c.stdin(subprocess_stdio_map(run_args.stdin.as_ref())?);
} else {
- c.stdin(subprocess_stdio_map(run_args.stdin.as_ref()));
+ let file = clone_file(run_args.stdin_rid, &mut resource_table)?;
+ c.stdin(file);
}
- let stdout_rid = run_args.stdout_rid;
- if stdout_rid > 0 {
- let file = clone_file(stdout_rid, &mut resource_table)?;
- c.stdout(file);
+ if run_args.stdout != "" {
+ c.stdout(subprocess_stdio_map(run_args.stdout.as_ref())?);
} else {
- c.stdout(subprocess_stdio_map(run_args.stdout.as_ref()));
+ let file = clone_file(run_args.stdout_rid, &mut resource_table)?;
+ c.stdout(file);
}
- let stderr_rid = run_args.stderr_rid;
- if stderr_rid > 0 {
- let file = clone_file(stderr_rid, &mut resource_table)?;
- c.stderr(file);
+ if run_args.stderr != "" {
+ c.stderr(subprocess_stdio_map(run_args.stderr.as_ref())?);
} else {
- c.stderr(subprocess_stdio_map(run_args.stderr.as_ref()));
+ let file = clone_file(run_args.stderr_rid, &mut resource_table)?;
+ c.stderr(file);
}
// We want to kill child when it's closed