From 5bc5dfdbda8d2dcfadccade112bbb7b97995a7e9 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Wed, 2 Sep 2015 11:33:31 +1000 Subject: [PATCH] cdless: Write to pipe in non-blocking mode so we don't get stuck if 'less' doesn't read everything --- cdless | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cdless b/cdless index ef344db1..f623d6b0 100755 --- a/cdless +++ b/cdless @@ -33,7 +33,8 @@ int main(int argc,array(string) argv) string txt=Charset.decoder(enc)->feed(data)->drain(); Stdio.File send=Stdio.File(),recv=send->pipe(); send->write("Selected encoding: %s\n\n",enc); - object proc=Process.create_process(({"less"}),(["stdin":recv])); - send->write(string_to_utf8(txt)); send->close(); - proc->wait(); + object proc=Process.create_process(({"less"}),(["stdin":recv,"callback":lambda(object p) {if (p->status()==2) exit(0);}])); + send->set_buffer_mode(0,Stdio.Buffer(string_to_utf8(txt))); + send->set_nonblocking(0,lambda() {send->close();}); + return -1; }