diff --git a/src/lune/builtins/process/mod.rs b/src/lune/builtins/process/mod.rs index 1cceef7..13c6a33 100644 --- a/src/lune/builtins/process/mod.rs +++ b/src/lune/builtins/process/mod.rs @@ -203,7 +203,7 @@ async fn spawn_command( options: ProcessSpawnOptions, ) -> LuaResult<(ExitStatus, Vec, Vec)> { let inherit_stdio = options.inherit_stdio; - let stdin = options.stdin.clone(); + let stdin = options.stdin; let mut child = options .into_command(program, args) @@ -218,10 +218,7 @@ async fn spawn_command( // If the stdin option was provided, we write that to the child if let Some(stdin) = stdin { let mut child_stdin = child.stdin.take().unwrap(); - child_stdin - .write_all(stdin.as_bytes()) - .await - .into_lua_err()?; + child_stdin.write_all(stdin).await.into_lua_err()?; } if inherit_stdio { diff --git a/src/lune/builtins/process/options.rs b/src/lune/builtins/process/options.rs index 316f6c9..47f5b48 100644 --- a/src/lune/builtins/process/options.rs +++ b/src/lune/builtins/process/options.rs @@ -14,7 +14,7 @@ pub struct ProcessSpawnOptions { pub(crate) envs: HashMap, pub(crate) shell: Option, pub(crate) inherit_stdio: bool, - pub(crate) stdin: Option, + pub(crate) stdin: Option<&'static [u8]>, } impl<'lua> FromLua<'lua> for ProcessSpawnOptions { @@ -138,8 +138,8 @@ impl<'lua> FromLua<'lua> for ProcessSpawnOptions { If we have stdin contents, we need to pass those to the child process */ match value.get("stdin")? { - LuaValue::Nil => {}, - LuaValue::String(s) => this.stdin = Some(s.to_string_lossy().to_string()), + LuaValue::Nil => {} + LuaValue::String(s) => this.stdin = Some(&*(s.as_bytes().to_vec().leak())), value => { return Err(LuaError::RuntimeError(format!( "Invalid type for option 'stdin' - expected 'string', got '{}'",