Skip to content

std::process::Command accepting arbitrary file extensions when env() specified #50870

Closed
@AndrewGaspar

Description

@AndrewGaspar

Description

On Windows, std::process::Command accepts arbitrary file extensions in place of the correct file extension (typically .exe) for a command when at least one environment variable is specified (e.g. command.env("FOO", "BAR")). The issue does not reproduce when no environment variables are specified.

Rust Version

> rustc --version
rustc 1.26.0 (a77568041 2018-05-07)

Minimum repro

use std::process::Command;

fn main() {
    Command::new("cmd.bannana")
        .env("FOO", "BAR")
        .args(&["/c", "echo", "hello"])
        .status()
        .unwrap();
}

Expected Result

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }', libcore\result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: process didn't exit successfully: `target\debug\command-ext-err.exe` (exit code: 101)

Actual Result

hello

Negative Reprodution

The following code snippet does NOT reproduce the issue.

use std::process::Command;

fn main() {
    Command::new("cmd.bannana")
        .args(&["/c", "echo", "hello"])
        .status()
        .unwrap();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-windowsOperating system: WindowsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions