Skip to content

Commit ca63a4e

Browse files
committed
Auto merge of #53404 - oconnor663:current_dir_behavior, r=alexcrichton
document the platform-specific behavior of Command::current_dir See also #37868. Here's my initial wording: > Note that if the program path is relative (e.g. `"./script.sh"`), the interaction between that path and `current_dir` varies across platforms. Windows currently ignores `current_dir` when locating the program, but Unix-like systems interpret the program path relative to `current_dir`. These implementation details aren't considered stable, and it's recommended to call `canonicalize` to get an absolute program path instead of using relative paths and `current_dir` together. I'd like to get feedback on: - _Should_ we consider those details stable? It might be disruptive to change them, regardless of what I can get away with claiming in docs :) - Is `canonicalize` an appropriate recommendation? As discussed in #37868 above, there are reasons it's not called automatically in the `Command` implementation.
2 parents f33921b + 0945b74 commit ca63a4e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libstd/process.rs

+10
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,14 @@ impl Command {
626626

627627
/// Sets the working directory for the child process.
628628
///
629+
/// # Platform-specific behavior
630+
///
631+
/// If the program path is relative (e.g. `"./script.sh"`), it's ambiguous
632+
/// whether it should be interpreted relative to the parent's working
633+
/// directory or relative to `current_dir`. The behavior in this case is
634+
/// platform specific and unstable, and it's recommended to use
635+
/// [`canonicalize`] to get an absolute program path instead.
636+
///
629637
/// # Examples
630638
///
631639
/// Basic usage:
@@ -638,6 +646,8 @@ impl Command {
638646
/// .spawn()
639647
/// .expect("ls command failed to start");
640648
/// ```
649+
///
650+
/// [`canonicalize`]: ../fs/fn.canonicalize.html
641651
#[stable(feature = "process", since = "1.0.0")]
642652
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command {
643653
self.inner.cwd(dir.as_ref().as_ref());

0 commit comments

Comments
 (0)