mirror of
https://github.com/lune-org/lune.git
synced 2025-04-20 03:43:49 +01:00
refactor: store raw bytes for stdin
This commit is contained in:
parent
224463da3a
commit
33730e1147
2 changed files with 5 additions and 8 deletions
|
@ -203,7 +203,7 @@ async fn spawn_command(
|
||||||
options: ProcessSpawnOptions,
|
options: ProcessSpawnOptions,
|
||||||
) -> LuaResult<(ExitStatus, Vec<u8>, Vec<u8>)> {
|
) -> LuaResult<(ExitStatus, Vec<u8>, Vec<u8>)> {
|
||||||
let inherit_stdio = options.inherit_stdio;
|
let inherit_stdio = options.inherit_stdio;
|
||||||
let stdin = options.stdin.clone();
|
let stdin = options.stdin;
|
||||||
|
|
||||||
let mut child = options
|
let mut child = options
|
||||||
.into_command(program, args)
|
.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 the stdin option was provided, we write that to the child
|
||||||
if let Some(stdin) = stdin {
|
if let Some(stdin) = stdin {
|
||||||
let mut child_stdin = child.stdin.take().unwrap();
|
let mut child_stdin = child.stdin.take().unwrap();
|
||||||
child_stdin
|
child_stdin.write_all(stdin).await.into_lua_err()?;
|
||||||
.write_all(stdin.as_bytes())
|
|
||||||
.await
|
|
||||||
.into_lua_err()?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if inherit_stdio {
|
if inherit_stdio {
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct ProcessSpawnOptions {
|
||||||
pub(crate) envs: HashMap<String, String>,
|
pub(crate) envs: HashMap<String, String>,
|
||||||
pub(crate) shell: Option<String>,
|
pub(crate) shell: Option<String>,
|
||||||
pub(crate) inherit_stdio: bool,
|
pub(crate) inherit_stdio: bool,
|
||||||
pub(crate) stdin: Option<String>,
|
pub(crate) stdin: Option<&'static [u8]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'lua> FromLua<'lua> for ProcessSpawnOptions {
|
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
|
If we have stdin contents, we need to pass those to the child process
|
||||||
*/
|
*/
|
||||||
match value.get("stdin")? {
|
match value.get("stdin")? {
|
||||||
LuaValue::Nil => {},
|
LuaValue::Nil => {}
|
||||||
LuaValue::String(s) => this.stdin = Some(s.to_string_lossy().to_string()),
|
LuaValue::String(s) => this.stdin = Some(&*(s.as_bytes().to_vec().leak())),
|
||||||
value => {
|
value => {
|
||||||
return Err(LuaError::RuntimeError(format!(
|
return Err(LuaError::RuntimeError(format!(
|
||||||
"Invalid type for option 'stdin' - expected 'string', got '{}'",
|
"Invalid type for option 'stdin' - expected 'string', got '{}'",
|
||||||
|
|
Loading…
Add table
Reference in a new issue