'head' closed its stdin, which was s3cmd's stdout, so s3cmd couldn't do sys.stdout.flush().

Here's a quick patch.  Also pull request https://github.com/s3tools/s3cmd/pull/242.

From 8fdf091bb7608dd16b03d885d546cbb51d02d684 Mon Sep 17 00:00:00 2001
From: Matt Domsch <matt@domsch.com>
Date: Tue, 12 Nov 2013 15:58:14 -0600
Subject: [PATCH] catch EPIPE and exit cleanly

---
 s3cmd | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/s3cmd b/s3cmd
index e8d06b8..300cfe2 100755
--- a/s3cmd
+++ b/s3cmd
@@ -2195,6 +2195,10 @@ if __name__ == '__main__':
         sys.stderr.write("See ya!\n")
         sys.exit(1)

+    except IOError, e:
+        if e.errno == errno.EPIPE: # sys.stdout was closed prematurely
+            sys.exit(0)
+
     except Exception, e:
         report_exception(e)
         sys.exit(1)
--
1.8.3.1



On Tue, Nov 12, 2013 at 1:00 PM, Yu Muyang <muyangy@andrew.cmu.edu> wrote:
I use the command line:
s3cmd ls s3://somewhere | head
and it reports:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    An unexpected error has occurred.
  Please report the following lines to:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Problem: IOError: [Errno 32] Broken pipe
S3cmd:   1.5.0-alpha3

Traceback (most recent call last):
  File "/usr/local/bin/s3cmd", line 2094, in <module>
    main()
  File "/usr/local/bin/s3cmd", line 2034, in main
    cmd_func(args)
  File "/usr/local/bin/s3cmd", line 104, in cmd_ls
    subcmd_bucket_list(s3, uri)
  File "/usr/local/bin/s3cmd", line 162, in subcmd_bucket_list
    "uri": uri.compose_uri(bucket, object["Key"]),
  File "/usr/local/bin/s3cmd", line 37, in output
    sys.stdout.flush()
IOError: [Errno 32] Broken pipe

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    An unexpected error has occurred.
    Please report the above lines to:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Sincerely,
Muyang Yu
________________________________________________
Muyang Yu
Master Candidate of ECE, Carnegie Mellon University
muyangy@andrew.cmu.edu
muyang.y@gmail.com







------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk