diff options
Diffstat (limited to 'src/pipeline/builtins/command.rs')
-rw-r--r-- | src/pipeline/builtins/command.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/pipeline/builtins/command.rs b/src/pipeline/builtins/command.rs index 8119a55..2e6b4af 100644 --- a/src/pipeline/builtins/command.rs +++ b/src/pipeline/builtins/command.rs @@ -1,5 +1,7 @@ use crate::pipeline::prelude::*; +use async_std::io::prelude::BufReadExt as _; + pub struct Command { exe: crate::parse::Exe, f: super::Builtin, @@ -196,16 +198,17 @@ impl Io { } } - pub async fn read_stdin(&self, buf: &mut [u8]) -> anyhow::Result<usize> { + pub async fn read_line_stdin(&self) -> anyhow::Result<String> { + let mut buf = String::new(); if let Some(fh) = self.stdin() { if let File::In(fh) = &mut *fh.lock_arc().await { - Ok(fh.read(buf).await?) - } else { - Ok(0) + fh.read_line(&mut buf).await?; } - } else { - Ok(0) } + if buf.ends_with('\n') { + buf.truncate(buf.len() - 1); + } + Ok(buf) } pub async fn write_stdout(&self, buf: &[u8]) -> anyhow::Result<()> { |