Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with std::process::Command on macOS. #80819

Closed
mmulet opened this issue Jan 8, 2021 · 2 comments
Closed

Issue with std::process::Command on macOS. #80819

mmulet opened this issue Jan 8, 2021 · 2 comments
Labels
C-bug Category: This is a bug. O-macos Operating system: macOS T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@mmulet
Copy link

mmulet commented Jan 8, 2021

I tried this code:

Directory structure:

.
+-- main.rs
+-- main
+-- sub_directory
|     +-- hello_world

main.rs:

use std::process::Command;
use std::path::Path;
fn main(){
    Command::new("./hello_world")
    .current_dir(Path::new("sub_directory"))
    .status()
    .expect("Failure to run");
}

I expected to see this happen:
Command should run the hello_world bash script located in ./sub_directory/hello_world. The exit code should be 0.

Instead, this happened:
Command does indeed run the hello_world bash script located in ./sub_directory/hello_world, but the exit code is 2 (Not found), and the main thread panics.
I noticed this issue only on macOS. I'm on macOS Big Sur 11.1 (20C69) on a Mac Pro (Late 2013). Works as expected in Linux.

I can create a workaround by creating an empty file named hello_world as a sibling to main.
Workaound directory structure:

.
+-- main.rs
+-- main
+-- sub_directory
|     +-- hello_world
+-- hello_world

Which leads me to believe that Command is trying to resolve a relative directory without taking into account the `.current_dir("...")" input and returning an incorrect exit status.

Meta

Checked Stable and nightly:

Stable:

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-apple-darwin
release: 1.49.0
Backtrace

thread 'main' panicked at 'Failure to run: Os { code: 2, kind: NotFound, message: "No such file or directory" }', test.rs:5:79
stack backtrace:
   0:        0x10038ec74 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha0848bb2602b5d05
   1:        0x1003a9690 - core::fmt::write::h9f3ccac2ef682b93
   2:        0x10038cd06 - std::io::Write::write_fmt::h0a47673aab280496
   3:        0x100390759 - std::panicking::default_hook::{{closure}}::h850c6aaf5e80c2f5
   4:        0x10039041d - std::panicking::default_hook::h037801299da6e1c6
   5:        0x100390ddb - std::panicking::rust_panic_with_hook::h76436d4cf7a368ac
   6:        0x100390905 - std::panicking::begin_panic_handler::{{closure}}::h516c76d70abf04f6
   7:        0x10038f0e8 - std::sys_common::backtrace::__rust_end_short_backtrace::h653290b4f930faed
   8:        0x10039086a - _rust_begin_unwind
   9:        0x1003ae0cf - core::panicking::panic_fmt::hde9134dd19c9a74f
  10:        0x1003adfd5 - core::option::expect_none_failed::h686aad664d56bca5
  11:        0x100377204 - core::result::Result<T,E>::expect::h4db214c9d11b030e
  12:        0x10037ae2e - test::main::h3085c8a5747c85a8
  13:        0x10037a00a - core::ops::function::FnOnce::call_once::h68c80bffef54ded6
  14:        0x100377c7d - std::sys_common::backtrace::__rust_begin_short_backtrace::h6c9d96006b516704
  15:        0x100377d00 - std::rt::lang_start::{{closure}}::h1b85b01ed6ecb62e
  16:        0x100391154 - std::rt::lang_start_internal::h36ccce6e8a047133
  17:        0x100377cd5 - std::rt::lang_start::h968f5e6067066713
  18:        0x10037ae92 - _main

Nightly:

rustc 1.51.0-nightly (c8915eebe 2021-01-07)
binary: rustc
commit-hash: c8915eebeaaef9f7cc1cff6ffd97f578b03c2ac9
commit-date: 2021-01-07
host: x86_64-apple-darwin
release: 1.51.0-nightly
Backtrace

thread 'main' panicked at 'Failure to run: Os { code: 2, kind: NotFound, message: "No such file or directory" }', test.rs:7:6
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c8915eebeaaef9f7cc1cff6ffd97f578b03c2ac9/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/c8915eebeaaef9f7cc1cff6ffd97f578b03c2ac9/library/core/src/panicking.rs:92:14
   2: core::option::expect_none_failed
             at /rustc/c8915eebeaaef9f7cc1cff6ffd97f578b03c2ac9/library/core/src/option.rs:1266:5
   3: core::result::Result<T,E>::expect
   4: test::main
   5: core::ops::function::FnOnce::call_once

@tmiasko
Copy link
Contributor

tmiasko commented Jan 8, 2021

PR with a workaround #80537 (this a bug in macOS posix_spawnp implementation).

@jonas-schievink jonas-schievink added T-libs Relevant to the library team, which will review and decide on the PR/issue. O-macos Operating system: macOS labels Jan 8, 2021
@mmulet
Copy link
Author

mmulet commented Jan 8, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-macos Operating system: macOS T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants