Hello.
I have simple shell script, which asks for input and return it:
#!/bin/sh
read -p "Enter something: " input
echo "You entered: $input"
Idea is to simulate more complicated utility that can return something after execution depends on condition. So my rust script looks:
fn main() {
let mut sh = Command::new("/usr/bin/sh");
let mut child = sh
.arg("-c").arg("/path_to/test_sh")
.stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped())
.spawn().unwrap();
let mut stdin = child.stdin.take().unwrap();
thread::spawn(move || {
stdin.write_all("asdf".as_bytes());
});
let output = child.wait_with_output().unwrap();
println!("OUT: {:?}", output);
The output is expected:
OUT: Output { status: ExitStatus(unix_wait_status(0)), stdout: "You entered: asdf\n", stderr: "" }
But where is my shell "Enter something: "?
How can I get it?
Is it possible to read it before any write to stdin?
Thank you advice.