with split bins poc
This commit is contained in:
11
pocs/split_bins/split_bins_cli/Cargo.toml
Normal file
11
pocs/split_bins/split_bins_cli/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "split_bins_cli"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = { version = "1.0.62", features = ["backtrace"] }
|
||||
ipc-channel = "0.16.0"
|
||||
serde = { version = "1.0.143", features = ["derive"] }
|
48
pocs/split_bins/split_bins_cli/src/main.rs
Normal file
48
pocs/split_bins/split_bins_cli/src/main.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use std::process::Command;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
println!("Hello, split_bins!");
|
||||
|
||||
println!("startup processes");
|
||||
|
||||
let executables = vec!["split_bins_plugin"]; //, "split_bins_plugin_two"];
|
||||
|
||||
let current_exe_path: String = get_current_exe_path()?;
|
||||
|
||||
let mut handles = vec![];
|
||||
for exe in executables {
|
||||
let curr_exe_path = current_exe_path.clone();
|
||||
let e = exe.clone();
|
||||
|
||||
handles.push(std::thread::spawn(move || {
|
||||
println!("current exe path: {}", curr_exe_path);
|
||||
let (server, name) =
|
||||
ipc_channel::ipc::IpcOneShotServer::new().expect("could not create oneshot server");
|
||||
|
||||
let mut child = Command::new(format!("{}/{}", curr_exe_path, e))
|
||||
.arg(format!("{}", name.clone()))
|
||||
.spawn()
|
||||
.expect(format!("started process: {}", curr_exe_path).as_str());
|
||||
|
||||
let (_, tx): (_, ipc_channel::ipc::IpcSender<String>) = server.accept().unwrap();
|
||||
tx.send("some msg".into()).expect("could not send message");
|
||||
|
||||
child.wait().expect("did not finish with 0");
|
||||
}));
|
||||
}
|
||||
|
||||
for handle in handles {
|
||||
if let Err(_) = handle.join() {
|
||||
return Err(anyhow::anyhow!("handle failed to return with statuscode=0"));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_current_exe_path() -> anyhow::Result<String> {
|
||||
let mut current_exe_path = std::env::current_exe()?;
|
||||
current_exe_path.pop();
|
||||
|
||||
return Ok(current_exe_path.to_string_lossy().to_string());
|
||||
}
|
Reference in New Issue
Block a user