浏览代码

Merge pull request #118 from gemmarx/ignore_brokenpipe

Change to ignore broken pipe error
Benjamin Sago 9 年之前
父节点
当前提交
3f81300e21
共有 1 个文件被更改,包括 11 次插入3 次删除
  1. 11 3
      src/bin/main.rs

+ 11 - 3
src/bin/main.rs

@@ -2,7 +2,7 @@ extern crate exa;
 use exa::Exa;
 use exa::Exa;
 
 
 use std::env::args;
 use std::env::args;
-use std::io::stdout;
+use std::io::{stdout, stderr, Write, ErrorKind};
 use std::process::exit;
 use std::process::exit;
 
 
 fn main() {
 fn main() {
@@ -10,9 +10,17 @@ fn main() {
     let mut stdout = stdout();
     let mut stdout = stdout();
 
 
     match Exa::new(&args, &mut stdout) {
     match Exa::new(&args, &mut stdout) {
-        Ok(mut exa) => exa.run().expect("IO error"),
+        Ok(mut exa) => if let Err(e) = exa.run() {
+            match e.kind() {
+                ErrorKind::BrokenPipe => exit(0),
+                _ => {
+                    writeln!(stderr(), "{}", e).unwrap();
+                    exit(1);
+                },
+            };
+        },
         Err(e) => {
         Err(e) => {
-            println!("{}", e);
+            writeln!(stderr(), "{}", e).unwrap();
             exit(e.error_code());
             exit(e.error_code());
         },
         },
     };
     };