Skip to content

Commit

Permalink
Merge pull request #34 from edouardpoitras/31-error-input
Browse files Browse the repository at this point in the history
Now using powershell command in windows examples
  • Loading branch information
edouardpoitras authored Mar 1, 2024
2 parents e5db7cc + 093ce2d commit 6d27502
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
3 changes: 1 addition & 2 deletions examples/despawn_on_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ fn startup(mut commands: Commands) {
#[cfg(not(windows))]
let cmd = LocalCommand::new("sh").args(["-c", "echo Sleeping for 1s && sleep 1 && echo Done"]);
#[cfg(windows)]
let cmd =
LocalCommand::new("cmd").args(["/C", "echo Sleeping for 1s && timeout 1 && echo Done"]);
let cmd = LocalCommand::new("powershell").args(["echo 'Sleeping for 1s'; sleep 1; echo Done"]);

let id = commands.spawn((cmd, Cleanup::DespawnEntity)).id();
println!("Spawned the command as entity {id:?}");
Expand Down
18 changes: 11 additions & 7 deletions examples/linux_input.rs → examples/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ fn main() {
}

fn startup(mut commands: Commands) {
let cmd = LocalCommand::new("sh")
.args(["-c", "echo 'Enter Name: ' && read NAME && echo Hello $NAME"]);
// Choose the command based on the OS
#[cfg(not(windows))]
let cmd =
LocalCommand::new("sh").args(["-c", "echo 'Enter Name:' && read NAME && echo Hello $NAME"]);
#[cfg(windows)]
let cmd = LocalCommand::new("powershell")
.args(["$name = Read-Host 'Enter Name'; echo \"Name Entered: $name\""]);
let id = commands.spawn(cmd).id();
println!("Spawned the command as entity {id:?}");
}
Expand All @@ -25,13 +30,12 @@ fn update(
) {
for process_output in process_output_event.read() {
for line in process_output.lines() {
println!("Output Line ({:?}): {line}", process_output.entity);
if line.ends_with(": ") {
let mut process = active_processes.get_mut(process_output.entity).unwrap();
process.println("Bevy").expect("Failed to write to process");
}
println!("{line}");
}
}
if let Ok(mut process) = active_processes.get_single_mut() {
process.println("Bevy").unwrap_or_default();
}
if let Some(process_completed) = process_completed_event.read().last() {
println!(
"Command {:?} completed (Success - {})",
Expand Down
5 changes: 2 additions & 3 deletions examples/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ fn startup(mut commands: Commands) {
"echo Sleeping for 4s && sleep 4 && echo This should not print or execute && sleep 100",
]);
#[cfg(windows)]
let cmd = LocalCommand::new("cmd").args([
"/C",
"echo Sleeping for 4s && timeout 4 && echo This should not print or execute && timeout 100",
let cmd = LocalCommand::new("powershell").args([
"echo 'Sleeping for 4s'; sleep 4; echo 'This should not print or execute'; sleep 100",
]);

let id = commands.spawn(cmd).id();
Expand Down
3 changes: 1 addition & 2 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ fn startup(mut commands: Commands) {
#[cfg(not(windows))]
let cmd = LocalCommand::new("sh").args(["-c", "echo Sleeping for 1s && sleep 1 && echo Done"]);
#[cfg(windows)]
let cmd =
LocalCommand::new("cmd").args(["/C", "echo Sleeping for 1s && timeout 1 && echo Done"]);
let cmd = LocalCommand::new("powershell").args(["echo 'Sleeping for 1s'; sleep 1; echo Done"]);

let id = commands.spawn(cmd).id();
println!("Spawned the command as entity {id:?}");
Expand Down

0 comments on commit 6d27502

Please sign in to comment.