- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to redirect STDERR to STDOUT for shell command...
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
тАО11-19-2010 03:57 AM
тАО11-19-2010 03:57 AM
How to redirect STDERR to STDOUT for shell command execution ?
I am going to use popen, faceing one difficulty to get the console output when command execution fails.
In Suse10 i am doing this way,
popen("ls -l aa > /dev/stdout 2>&1") where 'aa' directory is not present.
Actually here i am gettting error string from console without creating any extra temporary file.
How can i do the thing in HP-UX ?
-ashokd
- Tags:
- redirect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2010 05:11 AM
тАО11-19-2010 05:11 AM
Re: How to redirect STDERR to STDOUT for shell command execution ?
The order of redirection matters. I assume that you want to discard STDERR messages like those for non-existent operands.
# ls -l aa 2>/dev/null
In your case, you assigned file descriptor 2 to be the same as descriptor 1 whereas you want them segregated.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2010 06:50 AM
тАО11-19-2010 06:50 AM
Re: How to redirect STDERR to STDOUT for shell command execution ?
What hasn't been answered?
If you want to capture STDOUT in a temporary file, do something like:
# ls -l aa 2>/dev/null > mylog
...or, to write STDOUT to both your terminal and a file:
# ls -l aa 2>/dev/null | tee mylog
in either case, if 'aa' doesn't exist, 'mylog' will be empty by will be created anyway. Change '>' to '>>' or add '-a' to the 'tee' command to append to the file.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2010 11:12 PM
тАО11-19-2010 11:12 PM
Re: How to redirect STDERR to STDOUT for shell command execution ?
popen("ls -l aa > /dev/stdout 2>&1")
You don't want that output to go to the program? You could try /dev/tty instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2010 05:29 AM
тАО11-22-2010 05:29 AM
Re: How to redirect STDERR to STDOUT for shell command execution ?
if you want to get the result of the ls and the error messages on the pipe
popen("ls -l aa >/dev/tty 2>&1")
if you want to get the result on the current control terminal for that session.
popen("ls -l aa 2>&1 >/dev/tty") if you want to get the result to the control tty of the session but the error message to the pipe.