You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.
+-- main.rs
+-- main
+-- sub_directory
| +-- hello_world
main.rs:
use std::process::Command;use std::path::Path;fnmain(){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:
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.
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
The text was updated successfully, but these errors were encountered:
…v0 (#11452)
Works around #11406, which we found is due to rust-lang/rust#80819.
To workaround, we absolutify relative paths when they are argv[0]. We only do this for local execution.
I tried this code:
Directory structure:
main.rs:
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:
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
:Backtrace
Nightly:
Backtrace
The text was updated successfully, but these errors were encountered: