How to store a process in rust -


i'd store std::io::process::process inside struct in rust. however, program goes defunct pass process instance struct. why that? code:

use std::io::process::{command, process}; use std::rc::rc; use std::cell::refcell;  struct dzeninst {     process: rc<refcell<process>>     //stdin: std::io::pipe::pipestream }  impl dzeninst {     // write string stdin of dzen     fn write(&mut self, s : string) {         let mut stdin = self.process.borrow_mut().stdin.take().unwrap();         println!("writing dzen inst");         match stdin.write_str((s + "\n").as_slice()) {             err(why) => panic!("couldn't write dzen stdin: {}", why.desc),             ok(_) => println!("wrote string dzen"),         };     } }  fn createdzen() -> dzeninst {     dzeninst {process: rc::new(refcell::new(                 match command::new("dzen2").spawn() {                     err(why) => panic!("couldn't spawn dzen: {}", why.desc),                     ok(process) => process,                 }))} }  fn main() {     let mut d1 = createdzen();     d1.write("test".to_string());      std::io::timer::sleep(std::time::duration::duration::seconds(1));     } 

if write process stdin inside createdzen, works fine (i.e. program not go defunct). i'm assuming copying process instance causing destructor invoked, closes process. ideas how store process instance without causing process go defunct?

your rust code fine. problem here dzen2. need add -p flag make dzen2 persist eof (which in dzen2 readme).

instead of

match command::new("dzen2").spawn() { 

use

match command::new("dzen2").arg("-p").spawn() { 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -