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

Inconsistent behavior #36

Closed 0x7FFFFFFFFFFFFFFF closed 3 years ago

0x7FFFFFFFFFFFFFFF commented 3 years ago

I'm using version 1.2.2 and I have the following program.

fn main() -> eyre::Result<()> {
    std::env::set_current_dir(r##"f:\temp"##);
    let output = cmd_lib::spawn_with_output!(ls -la)?.wait_fun_result()?;

    println!("{:?}", output);
    Ok(())
}

When I run it, I can get the expected result like:

"total 5996106\ndrwxr-xr-x 1 admin None         0 Sep 25 16:26 .\n..............................."

When I change the command ls -la to more complex one (which probably takes several seconds to complete), I get empty output.

fn main() -> eyre::Result<()> {
    std::env::set_current_dir(r##"f:\temp"##);
    let output = cmd_lib::spawn_with_output!(
        ffmpeg -i 1.mp4 -i a2.png -y -filter_complex "overlay=x=263:y=752"  -c:a copy -max_muxing_queue_size 99999 -y test.mp4
    )?.wait_fun_result()?;

    println!("{:?}", output);
    Ok(())
}

Output is:

""

But can I find the produced output file of the ffmpeg command, which indicates the command did run. If I enabled the logger like this:

use cmd_lib::init_builtin_logger;
fn main() -> eyre::Result<()> {
    init_builtin_logger();
    std::env::set_current_dir(r##"f:\temp"##);
    let output = cmd_lib::spawn_with_output!(
        ffmpeg -i 1.mp4 -i a2.png -ss 00:00:00 -to 00:01:00 -y -filter_complex "overlay=x=263:y=752"  -c:a copy -max_muxing_queue_size 99999 -y testtttt.mp4
    )?.wait_fun_result()?;
    println!("{:?}", output);
    Ok(())
}

I can get the ffmpeg output in the console:

INFO - ffmpeg version N-103679-g7bbad32d5a-20210918 Copyright (c) 2000-2021 the FFmpeg developers
INFO -   built with gcc 10-win32 (GCC) 20210408
INFO -   configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-
...
INFO - [libx264 @ 0000010cf15da6c0] ref B L1: 97.3%  2.7%
INFO - [libx264 @ 0000010cf15da6c0] kb/s:134.12
""

But note the "" at the end of the output, I still can't get the output in the variable output and it still contains an empty string.

Why for simple command, the output is captured in a variable. But for complex command, it doesn't do this. Is this inconsistence a bug? How can I store the command output in a variable when the command is kinda complex? Thank.