io redirection doesn't work? 2>&1 >> logfile.log
hiho@ll
i tried command 2>&1 >> logfile.log to log everything (stdout and stderr) to a logfile i only get stdout! i also tried >> logfile 2>&1 the same! command &>> logfile.log i get an error &> logfile.log only gets stdout anybody knows how it REALY works? i searched the forum and the web and everybody thinks it's like the above methods but they don't work thx@ll |
Intreguing - I'd have thought that 2>&1 would redirect stderr into stdout - then you append stdout ... then >>file just sends stdout to the file ... so you're piping stderr to the screen and stdout to a file. To send them both you need two commands ... I'll see what google says just to check my suppositions.
<googles> I see what you mean ... however: I see it is OS/2 which redirects like this? ... did you see this one:http://www.cpqlinux.com/redirect.html ? It says: Quote:
Code:
cmd 1>>logfile.log 2>&1 Code:
cmd 2>>logfile.log 1>>logfile.log |
do you mean most bash scripting tutorials are wrong or not correct?
because http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html says 3.6 Sample: stderr and stdout 2 file This will place every output of a program to a file. This is suitable sometimes for cron entries, if you want a command to pass in absolute silence. rm -f $(find / -name core) &> /dev/null This (thinking on the cron entry) will delete every file called 'core' in any directory. Notice that you should be pretty sure of what a command is doing if you are going to wipe it's output. and &> didn't work too and i never found a script which says it only works for OS/2 i tryed your solution and it worked what did you search on google to find this? thx |
Quote:
the point you missed was that redirection works from right to left as Simon Bridge has pointed out so expertly so the proper command is command >logfile.log 2>&1 or command 1>logfile.log 2>&1 or command 2>logfile.log 1>&2 google for a tutorial called "rute tutorial" |
i'm not sure if i know what you mean
1. rute tutorial looks very good ;-) thx 2. the tutorial i search (the advanced bash scripting tutorial) explained io redirection (and it didn't work) --> i thought there was an failure in the tutorial so, why shouldn't the bash tutorial have anything to do with my topic? because: 3. i tried some example on a suse distri (very new, don't know exactly the version) i tried: cat * | grep "nothingfound" >> test.out 2>&1 bash did it, but there was nothing in test.out and cat throwed a few error messages (because it tried to cat a directory, which is what i wanted, because of the 2>&1 redirection ;-)) BUT: cat * >> test.out 2>&1 | grep "nothingfound" works (i know it's not very usefull example) i understand why, but it looks now as if 2>&1 works also using linux?? i thought it should "only" work on OS/2 if the above example works why doesn't work this: ./anyprogram >> test.out 2>&1 anyprogram is a self written prog (C++), which uses system command to execute some scripts, which could make error messages but if i cat test.out there is no Error message? is io redirection really as that complicated as it looks like (for me ):D thx@ll |
Well - I googles the line you tried "command 2>&1" and when I saw that all the tutorials had a little tag on the end (OS/2) just quite like - I appended "linux" to the search term. The site I told about was something like second.
You have to read these things carefully - the tutorials weren't wrong as such, they just included things which don't work in linux. They didn't claim anything for linux BTW. |
All times are GMT -5. The time now is 07:43 AM. |