1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// src/e_bacon.rs
use Error;
use Path;
use Command;
use crateCargoTarget;
// src/e_bacon.rs
// #[cfg(windows)]
// use std::os::windows::io::AsRawHandle;
/// Runs the "bacon" command on the given sample in detached mode,
/// capturing the output (stdout and stderr) into "output_bacon.txt".
/// It passes the project directory (derived from the sample’s manifest_path)
/// via the "--path" flag and appends any extra arguments.
///
/// On Windows, if the environment variable DEBUG_BACON is set, it uses `/K` and echoes
/// the folder parameter so that you can inspect it; otherwise it uses normal detached flags.
// /// Runs the "bacon" command on the given sample in detached mode,
// /// capturing the output (stdout and stderr) into "output_bacon.txt".
// /// It passes the project directory (derived from the sample’s manifest_path)
// /// via the "--path" flag and appends any extra arguments.
// pub fn run_bacon(sample: &Example, extra_args: &[String]) -> Result<(), Box<dyn Error>> {
// println!("Running bacon for sample: {}", sample.name);
// // Determine the project directory from the sample's manifest path.
// let manifest_path = Path::new(&sample.manifest_path);
// let project_dir = manifest_path.parent().unwrap_or(manifest_path);
// // Build the command.
// let mut cmd = Command::new("bacon");
// cmd.args(&["--path", project_dir.to_str().unwrap_or_default()]);
// if !extra_args.is_empty() {
// cmd.args(extra_args);
// }
// // Open an output file to capture the output.
// // This file will be created (or overwritten) in the current working directory.
// let output_file = std::fs::File::create("output_bacon.txt")?;
// // Redirect stdout and stderr to the output file.
// cmd.stdout(Stdio::from(output_file.try_clone()?))
// .stderr(Stdio::from(output_file));
// // Platform-specific process detachment.
// #[cfg(windows)]
// {
// // DETACHED_PROCESS (0x00000008) and CREATE_NEW_PROCESS_GROUP (0x00000200)
// // are required on Windows to detach the child process.
// const DETACHED_PROCESS: u32 = 0x00000008;
// const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200;
// cmd.creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP);
// }
// #[cfg(not(windows))]
// {
// // On Unix-like systems, simply redirecting the standard I/O is enough to detach.
// // (Optionally you could also use a daemonizing library or fork the process.)
// }
// // Spawn the bacon process detached. We do not wait on it.
// let _child = cmd.spawn()?;
// println!("Bacon process detached; output is captured in 'output_bacon.txt'.");
// Ok(())
// }
// src/e_bacon.rs
// pub fn run_bacon(sample: &Example, extra_args: &[String]) -> Result<(), Box<dyn Error>> {
// println!("Running bacon for sample: {}", sample.name);
// // Determine the project directory from the sample's manifest_path.
// let manifest_path = std::path::Path::new(&sample.manifest_path);
// let project_dir = manifest_path.parent().unwrap_or(manifest_path);
// let mut cmd = Command::new("bacon");
// cmd.args(&["--path", project_dir.to_str().unwrap_or_default()]);
// if !extra_args.is_empty() {
// cmd.args(extra_args);
// }
// // Detach on Windows.
// #[cfg(windows)]
// {
// const DETACHED_PROCESS: u32 = 0x00000008;
// const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200;
// cmd.creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP);
// }
// // On Unix-like systems, detach by redirecting standard I/O.
// #[cfg(not(windows))]
// {
// cmd.stdin(Stdio::null())
// .stdout(Stdio::null())
// .stderr(Stdio::null());
// }
// // Spawn the bacon process (detached).
// let _child = cmd.spawn()?;
// println!("Bacon process detached.");
// Ok(())
// }