Skip to content

Commit

Permalink
cdless: Write to pipe in non-blocking mode so we don't get stuck if '…
Browse files Browse the repository at this point in the history
…less' doesn't read everything
  • Loading branch information
Rosuav committed Sep 2, 2015
1 parent cd1c29a commit 5bc5dfd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cdless
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 5bc5dfd

Please sign in to comment.