rust-shell-script / rust_cmd_lib

Common rust command-line macros and utilities, to write shell-script like tasks in a clean, natural and rusty way
https://docs.rs/cmd_lib/
Apache License 2.0
1.05k stars 37 forks source link

dynamic redirection and piping #54

Closed bjarthur closed 2 years ago

bjarthur commented 2 years ago

i have a string literal which contains a pipe (|) and/or and angle bracket (e.g. >). i'd like this to work just like in bash. is this possible somehow? i've read the section on using vectors for dynamic parameters. see discussion on discourse. something like this:

    let args = shell_words::split("echo hi > echo.out").unwrap();
    let child = spawn!($[args]).unwrap();
bjarthur commented 2 years ago

i'd be happy to help add this feature if you can point me in the right direction

rust-shell-script commented 2 years ago

You can create a different library to do that, as this library will never do something like this due to above mentioned shell injection risk. If possible, running with bash -c can also make things work, however it would also introduce all other risks.

You can do the parsing by yourself then, and call this library's GroupCmds/Cmds/Cmd APIs to finish the remaining work. You can check the unit tests in src/process.rs or run cargo expand to see how the lower level APIs are being called.