SPUG: redirect close
cwilkes-spug at ladro.com
Mon Aug 26 13:19:55 CDT 2002
On Mon, Aug 26, 2002 at 10:00:16AM -0700, Baker, Stephen M wrote:
> I'm maintaining a program where I constantly see
> which I believe redirects STDOUT to STDIN, but regardless of what exactly it
> does I'm aware its a redirect of some kind and I would really like to know
> its scope for declaration and how to cut it off. Is it limited to the block
> it is declared in, or does this type of command continue to live on outside
> of a give code block.
I take it that this is in some perl code, something like:
$ret = `cp a.txt b.txt 2>&1`;
If a.txt doesn't exist you'll get an error printed to STDERR of "no such
file" -- which is captured with the above syntax. If you didn't have it
there the error would come up on your screen and $ret wouldn't have this
Note: this just isn't for built in shell functions returning errors, it
could be for anything, even another perl script that might print
debugging info to STDERR. Its also handy if you don't want to see
stderr output on the screen.
Since you're forking a new process the 2>&1 redirect will only be
around for that process. The next time you do a system call the stderr
will go to the same place as it normally goes.
There's a lot of info in the perldocs if you type 'perldoc -q stderr'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list