Archives / Search ›

Shell redirection pain

I’m still learning more about zsh every week, trying to solve various problems and improve my productivity using its many features. Of course, it doesn’t hurt to show off from time to time either. :-)

Here’s a seemingly simple thing that’s stumped me tonight: how to display stdout from a process as it’s generated, and pipe it to another program at the same time. The MULTIOS feature makes this simple if it were two files, but it isn’t. The closest I could get, which admittedly isn’t very close, is foo >&2 | bar, but that waits until foo finishes before displaying anything, in a way it doesn’t if the | bar is missing.

In actuality, bar is the bbedit tool—I’m wanting to open the results in a BBEdit window if foo successfully finishes. The ideal tool for this would be BBEdit’s shell worksheet, but it also waits until foo has finished before displaying any output.

Update: Duh, I’ve seen and solved this problem before. foo is actually a Python script, and something in Python or the C library’s standard I/O routines thought I was redirecting to something that wasn’t a terminal, therefore it should be more efficient about flushing. Adding a strategically placed instance of sys.stdout.flush() caused the above incantation to work fine.

No comments yet. Be the first.

Leave a reply