-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question on struck when interacting with subprocess #67
Comments
If the "some lines of strings" are self-delimited (i.e. you are able to detect when they are done), then you could simply read from |
Actually, I would like to listen to the output of this app within a time limit after sending input to it. In dart, I could do it like this: Future<Process?> init() {
ready = false;
if (!isSupportEngine) {
return Future.value(null);
}
// path to the process app
String path = Directory.current.path + '/assets/engines/$engine';
if (!File(path).existsSync()) {
path = Directory.current.path +
'/data/flutter_assets/assets/engines/$engine';
}
return Process.start(path, [], mode: ProcessStartMode.normal).then((value) {
process = value;
ready = true;
process?.stdout.listen(onMessage);
process?.stdin.writeln('ucci');
return process!;
});
}
void onMessage(List<int> event) {
String lines = String.fromCharCodes(event).trim();
lines.split('\n').forEach((line) {
line = line.trim();
if (line == 'bye') {
ready = false;
process = null;
} else if (line.isNotEmpty && this.hasListeners) {
if (line.startsWith('nobestmove') || line.startsWith('bestmove ')) {
...
this.notifyListeners(line);
}
}
});
} But I don't know how to do it in rust. let cmd = "./myShellApp.exe";
let mut p = Popen::create(
&[cmd],
PopenConfig {
stdin: Redirection::Pipe,
stdout: Redirection::Pipe,
..Default::default()
},
)
.expect("open app failed");
p.stdin
.as_mut()
.unwrap()
.write_all(b"ucci\n")?;
if let Some(status) = p.wait_timeout(Duration::new(2, 0)).unwrap() {
println!("process finished as {:?}", status);
let x = &p.stdout;
} else {
p.kill().unwrap();
p.wait().unwrap();
println!("process killed");
} It still killed the process. What is wrong? |
I have a shell app. Generally, I would open it in a shell, then I input a command "ucci" to it, then it feedbacks some lines of strings. And I would still interact it with other commands until I input "quit", then it would quit.
I wrote code like this:
But the code just stuck at
let (out, err) = p.communicate(Some("ucci\n"))?;
. It seems that it would not quit until the sub process in terminated. How should I fix it?The text was updated successfully, but these errors were encountered: