Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing console input to a command? #61

Open
spemmons opened this issue Dec 21, 2024 · 1 comment
Open

Passing console input to a command? #61

spemmons opened this issue Dec 21, 2024 · 1 comment

Comments

@spemmons
Copy link

currently all the stdin options for a command are predefined files, bytes, etc.

would it be possible to connect to the stdin of the command with a loop reading user input and feeding it to the process?

@oconnor663
Copy link
Owner

oconnor663 commented Dec 21, 2024

Normally reading user input from the terminal is the default behavior if you don't change anything. For example this program:

use duct::cmd;

fn main() {
    println!("gonna start Python");
    cmd!("python").run().unwrap();
    println!("Python exited");
}

Does this (where cargo run and exit() are my keyboard input):

$ cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/scratch`
gonna start Python
Python 3.12.7 (main, Oct  1 2024, 11:15:50) [GCC 14.2.1 20240910] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
Python exited
$

(The same is true of std::process::Command.) Does that help at all, or was that already clear?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants