add command-wait-silent

This commit is contained in:
Daniella / Tove 2024-11-22 13:16:09 +01:00
parent 8c2b6724da
commit 4357a16523
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -829,6 +829,14 @@ pub fn command(stack: &mut Stack) -> OError {
}
pub fn command_wait(stack: &mut Stack) -> OError {
command_wait_impl(stack, Stdio::inherit)
}
pub fn command_wait_silent(stack: &mut Stack) -> OError {
command_wait_impl(stack, Stdio::null)
}
pub fn command_wait_impl(stack: &mut Stack, stdio: fn() -> Stdio) -> OError {
let binding = stack.pop();
let Value::Array(ref a) = binding.lock_ro().native else {
return stack.err(ErrorKind::InvalidCall("command".to_owned()));
@ -848,9 +856,9 @@ pub fn command_wait(stack: &mut Stack) -> OError {
Value::Int(
process::Command::new(&args[0])
.args(&args[1..])
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.stdin(stdio())
.stdout(stdio())
.stderr(stdio())
.spawn()
.map_err(|x| stack.error(ErrorKind::IO(x.to_string())))?
.wait()
@ -1150,7 +1158,7 @@ pub fn chdir(stack: &mut Stack) -> OError {
pub fn register(r: &mut Stack, o: Arc<Frame>) {
type Fn = fn(&mut Stack) -> OError;
let fns: [(&str, Fn, u32); 69] = [
let fns: [(&str, Fn, u32); 70] = [
("pop", pop, 0),
("dup", dup, 2),
("dup2", dup2, 3),
@ -1203,6 +1211,7 @@ pub fn register(r: &mut Stack, o: Arc<Frame>) {
("readln", readln, 1),
("command", command, 1),
("command-wait", command_wait, 1),
("command-wait-silent", command_wait_silent, 1),
("str-to-bytes", str_to_bytes, 1),
("bytes-to-str", bytes_to_str, 1),
("acopy", acopy, 1),