File tree Expand file tree Collapse file tree
src/coding-guidelines/program-structure-and-compilation Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3737 use std::io;
3838
3939 fn files (dir: &str) -> io::Result<Output> {
40+ let lsdir_cmd = if cfg!(unix) { " ls" } else { " dir" };
4041 return Command::new (" sh" )
4142 .arg (" -c" )
42- .arg (format!(" ls {dir}" ))
43+ .arg (format!(" {lsdir_cmd} {dir}" ))
4344 .output ();
4445 }
4546
4950 }
5051 }
5152
52-
5353 .. compliant_example::
5454 :id: compl_ex_rJeLKhdopITN
5555 :status: draft
6262 use std::io;
6363
6464 fn files (dir: &str) -> io::Result<Output> {
65- return Command::new (" ls" )
66- .arg (dir)
65+ let lsdir_cmd = if cfg!(unix) { " ls" } else { " dir" };
66+ return Command::new (" sh" )
67+ .arg (" -c" )
68+ .arg (format!(" {lsdir_cmd} {dir}" ))
6769 .output ();
6870 }
6971
7072 fn main () {
7173 if cfg!(unix) {
72- let _ = files (" dummy | echo BOO" ); // Command is invalid, but does not print BOO
74+ let _ = files (" dummy | echo BOO" ); // Program prints " BOO"
7375 }
7476 }
7577
76-
7778 .. compliant_example::
7879 :id: compl_ex_BSjAFOLfL4Rk
7980 :status: draft
You can’t perform that action at this time.
0 commit comments