Skip to content

Issue with xargs parsing #142

@wolfv

Description

@wolfv

A user of pixi reported that piping stdin into deno_task_shell has an issue (prefix-dev/pixi#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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions