- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- redirecting stdin & stdout
Operating System - HP-UX
1819803
Members
3197
Online
109607
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 12:59 AM
тАО02-07-2002 12:59 AM
hi all,
I am having trouble getting the 2>&1 ethic to work
I am simply trying :
lsf 2>&1 redirect_test
1- The statement won't work if the file is not previously created (??)
2- If the file is created, the output(s) are still not written
I know this is basic, but I just can't get it to work. (I have also tried an example from the HP certified book - can't get that to work either)
any help will be much appreciated,
thanks
John
I am having trouble getting the 2>&1 ethic to work
I am simply trying :
lsf 2>&1 redirect_test
1- The statement won't work if the file is not previously created (??)
2- If the file is created, the output(s) are still not written
I know this is basic, but I just can't get it to work. (I have also tried an example from the HP certified book - can't get that to work either)
any help will be much appreciated,
thanks
John
chicken or egg first?
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 01:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 01:22 AM
тАО02-07-2002 01:22 AM
Re: redirecting stdin & stdout
The following works just as well, and is less confusing:
lsf 1>redirect_test 2>redirect_test
lsf 1>redirect_test 2>redirect_test

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 06:49 AM
тАО02-07-2002 06:49 AM
Re: redirecting stdin & stdout
Hi John,
It appears you are trying to redirect standard output (file descriptor 1) and standard error (fd 2) to redirect_test. Bear with me in this explanation.
In Bourne shell and its derivitives (ie Korn and Posix) output to a file can be redirected with #> where # is the file descriptor number (1 = stdout, 2 = stderr, others as defined by the process). The default for # is 1. Therefore 1> is the same as >. So to redirect stdout use >outfile. To redirect stderr use 2>errfile. To redirect stdout and stderr to the same file use:
command >file 2>&1
Note that with 2>&1 stderr (fd 2) is redirected to the same file as stdout (fd 1).
The order in which redirection is specified is important. Consider the following 2 examples:
command >outfile 2>&1
command 2>&1 >outfile
The first example redirects stdout to outfile then redirects stderr to the same file used by stdout (outfile). Thus output and errors are written to outfile.
The second example redirects stderr to the same file used by stdout which since stdout has yet to be redirected is by default the screen. Then stdout is redirected to outfile. The result is that output is written to outfile but errors are written to the screen.
Test the above as follows:
mkdir testdir
cd testdir
ls junk >outfile 2>&1
ls junk 2>&1 >outfile
Finally, to your problem.
lsf 2>&1 redirect_test
redirect_test is being seen as an argument to lsf. It it does not exist, you get the error "redirect_test not found". The error is sent to stderr which is redirected to the same file as stdout and is printed on the screen. If redirect_test exists, the lsf command writes "redirect_test" to stdout (the screen).
The commonly used syntax you need is:
lsf >redirect_test 2>&1
The more fully qualified syntax (with the same results as the commonly used syntax) is:
lsf 1>redirect_test 2>redirect_test
See the man pages for sh-bourne or sh-posix for more info. Also, if you use csh, man csh. csh is a much different animal.
Darrell
It appears you are trying to redirect standard output (file descriptor 1) and standard error (fd 2) to redirect_test. Bear with me in this explanation.
In Bourne shell and its derivitives (ie Korn and Posix) output to a file can be redirected with #> where # is the file descriptor number (1 = stdout, 2 = stderr, others as defined by the process). The default for # is 1. Therefore 1> is the same as >. So to redirect stdout use >outfile. To redirect stderr use 2>errfile. To redirect stdout and stderr to the same file use:
command >file 2>&1
Note that with 2>&1 stderr (fd 2) is redirected to the same file as stdout (fd 1).
The order in which redirection is specified is important. Consider the following 2 examples:
command >outfile 2>&1
command 2>&1 >outfile
The first example redirects stdout to outfile then redirects stderr to the same file used by stdout (outfile). Thus output and errors are written to outfile.
The second example redirects stderr to the same file used by stdout which since stdout has yet to be redirected is by default the screen. Then stdout is redirected to outfile. The result is that output is written to outfile but errors are written to the screen.
Test the above as follows:
mkdir testdir
cd testdir
ls junk >outfile 2>&1
ls junk 2>&1 >outfile
Finally, to your problem.
lsf 2>&1 redirect_test
redirect_test is being seen as an argument to lsf. It it does not exist, you get the error "redirect_test not found". The error is sent to stderr which is redirected to the same file as stdout and is printed on the screen. If redirect_test exists, the lsf command writes "redirect_test" to stdout (the screen).
The commonly used syntax you need is:
lsf >redirect_test 2>&1
The more fully qualified syntax (with the same results as the commonly used syntax) is:
lsf 1>redirect_test 2>redirect_test
See the man pages for sh-bourne or sh-posix for more info. Also, if you use csh, man csh. csh is a much different animal.
Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP