[CALUG] More I/O buffering foolishness
James Ewing Cottrell 3rd
JECottrell3 at Comcast.NET
Wed Mar 1 15:26:32 CST 2006
Your problem may be with tar itself. Tar may be looking to see whether
or not your stdin/stdout/stderr is a terminal and doing different
things. Your perl script looks OK, but try using cat instead, or pipe to
"cat -n > /tmp/$$" and see if you get your output numbered.
In fact, the script itself may have no stdout defined! This is the most
likely explanation if your script is being run by an X program.
I do have a few suggestions for you, however. First, any shell script
(including ones inside parens, as you have) should probably use "exec"
on the last command. This replaces the two shells with tar instead of
keeping them around. Second, the shells themself are unnecessay, as tar
has a "-C /dir" set of arguments. Try:
tar cf - . -C /blah | tar xf - -C /blah2
or even better, use "rsync -a /blah/. /blah2/." Note that rsync is picky
about whether you end your paths with slashes or not. However, until you
understand the rules, it's just easier to add the trailing dots, knoing
that however the rules are applied, What You Expect will happen.
JIM
Jason C. Miller wrote:
> I've asked a buffering question on here before and have now run into a
> similar-yet-different issue and was wondering if anyone had any insight.
>
> Here's the short story...
>
>
> At the command line (bash) ...
> -----------------------------------
> (cd /blah ; tar cvf - * 2>/dev/null) | (cd /blah2 ; tar xvf - 2>/tmp/log) | \
> perl -e 'while (<STDIN>) { print }'
> -----------------------------------
> ... works fine. All it does is print the stdout from the tar extraction.
>
>
> However, once inserted into a script, the exact same string of commands
> will be block-buffered instead of line-buffered (ie. prints output in
> chunks). Granted, this isn't unheard of. This is particularly annoying
> because the stdin is being used as input for another program (Xdialog).
>
>
> The oddness is that, inside the script ...
> -----------------------------------
> (cd /blah ; tar cvf - * 2>/dev/null) | (cd /blah2 ; tar xvf - 2>/tmp/log)
> -----------------------------------
> ... will line-buffer just fine. It's when I try to pipe that into
> anything else AFTER that the buffering issues come up. I've tried it with
> both perl and awk and they both do the same thing. I tried forcing the
> flush in the perl, but that doesn't do anything and I really don't know if
> that's the issue or not.
>
>
> Any ideas?
>
> -jason
>
> _______________________________________________
> Columbia, Maryland Linux User's Group (CALUG) mailing list
> CALUG Website: http://www.calug.com
> Email postings to: lug at calug.com
> Change your list subscription options: http://calug.com/mailman/listinfo/lug
>
More information about the lug
mailing list