1use bevy::prelude::*;
2use bevy_local_commands::{BevyLocalCommandsPlugin, LocalCommand, ProcessCompleted, ProcessOutput};
3
4fn main() {
5 App::new()
6 .add_plugins((MinimalPlugins, BevyLocalCommandsPlugin))
7 .add_systems(Startup, startup)
8 .add_systems(Update, update)
9 .run();
10}
11
12fn startup(mut commands: Commands) {
13 #[cfg(not(windows))]
15 let cmd = LocalCommand::new("sh").args(["-c", "echo Sleeping for 1s && sleep 1 && echo Done"]);
16 #[cfg(windows)]
17 let cmd = LocalCommand::new("powershell").args(["echo 'Sleeping for 1s'; sleep 1; echo Done"]);
18
19 let id = commands.spawn(cmd).id();
20 println!("Spawned the command as entity {id:?}");
21}
22
23fn update(
24 mut process_output_event: MessageReader<ProcessOutput>,
25 mut process_completed_event: MessageReader<ProcessCompleted>,
26) {
27 for process_output in process_output_event.read() {
28 for line in process_output.lines() {
29 println!("Output Line ({:?}): {line}", process_output.entity);
30 }
31 }
32 if let Some(process_completed) = process_completed_event.read().last() {
33 println!(
34 "Command {:?} completed (Success - {})",
35 process_completed.entity,
36 process_completed.exit_status.success()
37 );
38 std::process::exit(0);
40 }
41}