deno_task_shell icon indicating copy to clipboard operation
deno_task_shell copied to clipboard

Issue with `xargs` parsing

Open wolfv opened this issue 8 months ago • 1 comments

A user of pixi reported that piping stdin into deno_task_shell has an issue (https://github.com/prefix-dev/pixi/issues/3462)

I created the folling reproducer:

use std::env;
use std::collections::HashMap;
use anyhow::{Context, Result};
use tokio;

#[tokio::main]
async fn main() -> Result<()> {
    // Join the command and its arguments
    let command_text = "xargs -0 printf '%s XXX'";
    // let command_text = "which xargs";

    // Parse the command
    let list = deno_task_shell::parser::parse(&command_text)
        .with_context(|| format!("Failed to parse command '{}'", command_text))?;

    // Setup execution environment
    let env_vars = std::env::vars().collect::<HashMap<_, _>>();
    let cwd = std::env::current_dir()?;

    // Execute the command
    let exit_code = deno_task_shell::execute(
        list,
        env_vars,
        &cwd,
        Default::default(), // custom commands
        Default::default(), // custom env
    ).await;

    // Exit with the same code as the command
    std::process::exit(exit_code);
}

When running:

printf 'a\0b\0' | cargo r --example repro

It prints a XXXb XXX XXX

While on a regular terminal,

╰─$ printf 'a\0b\0' | xargs -0 printf '%s XXX'
a XXXb XXX%                                                                                  

is printed.

Any ideas?

wolfv avatar Mar 31 '25 12:03 wolfv

Probalby an issue in https://github.com/denoland/deno_task_shell/blob/main/src/shell/commands/xargs.rs

dsherret avatar Apr 01 '25 20:04 dsherret