Skip to content

Commit f281a76

Browse files
authored
Rollup merge of #78599 - panstromek:master, r=m-ou-se
Add note to process::arg[s] that args shouldn't be escaped or quoted This came out of discussion on [forum](https://users.rust-lang.org/t/how-to-get-full-output-from-command/50626), where I recently asked a question and it turned out that the problem was redundant quotation: ```rust Command::new("rg") .arg("\"pattern\"") // this will look for "pattern" with quotes included ``` This is something that has bitten me few times already (in multiple languages actually), so It'd be grateful to have it in the docs, even though it's not sctrictly Rust specific problem. Other users also agreed. This can be really annoying to debug, because in many cases (inluding mine), quotes can be legal part of the argument, so the command doesn't fail, it just behaves unexpectedly. Not everybody (including me) knows that quotes around arguments are part of the shell and not part of the called program. Coincidentally, somoene had the same problem [yesterday](https://www.reddit.com/r/rust/comments/jkxelc/going_crazy_over_running_a_curl_process_from_rust/) on reddit. I am not a native speaker, so I welcome any corrections or better formulation, I don't expect this to be merged as is. I was also reminded that this is platform/shell specific behaviour, but I didn't find a good way to formulate that briefly, any ideas welcome. It's also my first PR here, so I am not sure I did everything correctly, I did this just from Github UI.
2 parents 25eac92 + db416b2 commit f281a76

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

library/std/src/process.rs

+10
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ impl Command {
557557
///
558558
/// [`args`]: Command::args
559559
///
560+
/// Note that the argument is not passed through a shell, but given
561+
/// literally to the program. This means that shell syntax like quotes,
562+
/// escaped characters, word splitting, glob patterns, substitution, etc.
563+
/// have no effect.
564+
///
560565
/// # Examples
561566
///
562567
/// Basic usage:
@@ -582,6 +587,11 @@ impl Command {
582587
///
583588
/// [`arg`]: Command::arg
584589
///
590+
/// Note that the arguments are not passed through a shell, but given
591+
/// literally to the program. This means that shell syntax like quotes,
592+
/// escaped characters, word splitting, glob patterns, substitution, etc.
593+
/// have no effect.
594+
///
585595
/// # Examples
586596
///
587597
/// Basic usage:

0 commit comments

Comments
 (0)