Skip to content

Commit 8a31c99

Browse files
committed
Tried to make code platform-independent
1 parent 8bf8735 commit 8a31c99

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/coding-guidelines/program-structure-and-compilation/gui_J3K3ZqC8qoOn.rst.inc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
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

@@ -49,7 +50,6 @@
4950
}
5051
}
5152

52-
5353
.. compliant_example::
5454
:id: compl_ex_rJeLKhdopITN
5555
:status: draft
@@ -62,18 +62,19 @@
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

0 commit comments

Comments
 (0)