Sponsored Content
Top Forums Shell Programming and Scripting Preserve output order when redirecting stdout and stderr Post 302382473 by Boemm on Wednesday 23rd of December 2009 10:31:23 AM
Old 12-23-2009
Hi radoulov,

thanks for you reply.

I tried the version with expect, but this didn't work for all aspects.
If tried both of my commands executing by "unbuffer" but the error.log was never filled.
For me those great tools was new, but I searched around for infos about and the reason for the empty error.log is, that expect merges the stdout and stderr together internal and afterwards the information, where the output comes from (stderr or stdout) is gone away.
So one cannot separate while catching each separate line with expect to whether write it to output.log or to error.log.
Was a nice try and maybe this tools helps me out with other works ;-) but on this particular problem I found no solution with this.

The other idea, to prepend some line numbering to each line, was also in my mind.
The problem is, I cannot add this for each line, since in my special case, I execute some php scripts and if php throws some fatal errors there is no possibility to catch those errors to prepend some number.

The same problem would be with some binary executables.
There is also no possibility to prepend line numbers before each output line ...

So if there is no way to use some wrapper "around" the binary or php script, which adds the leading numbers and preserves the channel where the output was written (so that stdout still is stdout and stderr still is stderr) this is not a working solution for my problem ...

Do you know such a wrapper somewhere in the wild!?

:-)
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

sending syslog output to stderr or stdout

Is there a way to send the syslog output for a given facility to stderr or stdout? I do not want to use the "tail" command to achieve this, I would like it to go directly to stderr. Thanks in advance (1 Reply)
Discussion started by: dmirza
1 Replies

2. Shell Programming and Scripting

redirecting STDOUT & STDERR

In bash, I need to send the STDOUT and STDERR from a command to one file, and then just STDERR to another file. Doing one or the other using redirects is easy, but trying to do both at once is a bit tricky. Anyone have any ideas? (9 Replies)
Discussion started by: jshinaman
9 Replies

3. Shell Programming and Scripting

getting stderr & stdout output lively modified

This is about getting all output to stderr and stdout localized. Nothing to do with redirecting output to a file (there already are some interesting threads about that issue on this forum). What I intend to do is capturing all lines of text sent to the screen, compare them with an array of... (2 Replies)
Discussion started by: teo ramirez
2 Replies

4. Shell Programming and Scripting

Redirecting STDERR message to STDOUT & file at same time

Friends I have to redirect STDERR messages both to screen and also capture the same in a file. 2 > &1 | tee file works but it also displays the non error messages to file, while i only need error messages. Can anyone help?? (10 Replies)
Discussion started by: vikashtulsiyan
10 Replies

5. Shell Programming and Scripting

Redirecting part of output to stdout

Hi, I am trying to execute a command like this: find ./ -name "*.gz" -exec sh -c 'zcat {} | awk -f parse.awk' \; >> output If I want to print the filename, i generally use the -print argument to the find command but when I am redirecting the output to a file, how can I print just the... (2 Replies)
Discussion started by: Legend986
2 Replies

6. Shell Programming and Scripting

redirect stdout and stderr to file wrong order problem with subshell

Hello I read a lot of post related to this topic, but nothing helped me. :mad: I'm running a ksh script with subshell what processing some ldap command. I need to check output for possible errors. #!/bin/ksh ... readinput < $QCHAT_INPUT |& while read -p line do echo $line ... (3 Replies)
Discussion started by: Osim
3 Replies

7. Shell Programming and Scripting

File descriptors, redirecting output, and stdout

Hello all. I've been lurking here for a year or two and finally decided to post. I need some assistance with file descriptors, stdout, and redirecting output. I've searched through a number of very helpful threads here (unfortunately I can't link to any of them yet due to my low post count...),... (2 Replies)
Discussion started by: Michael_K
2 Replies

8. Shell Programming and Scripting

Redirecting STDERR to file and screen, STDOUT only to file

I have to redirect STDERR messages both to screen and also capture the same in a file but STDOUT only to the same file. I have searched in this formum for a solution, but something like srcipt 3>&1 >&2 2>&3 3>&- | tee errs doesn't work for me... Has anyone an idea??? (18 Replies)
Discussion started by: thuranga
18 Replies

9. Shell Programming and Scripting

Lost redirecting stderr & stdout to 3 files - one each plus combined

Hi folks I need/want to redirect output (stdout, stderr) from an exec call to separate files. One for stderr only and two(!) different (!) ones for the combined output of stderr and stdout. After some research and testing i got this so far : (( exec ${command} ${command_parameters} 3>&1... (6 Replies)
Discussion started by: MDominok
6 Replies

10. Shell Programming and Scripting

Redirecting stdout output to whiptail menu box

As a result of whiptail menu option I am getting a data from a file. Naturally it is output to terminal as stdour. I like to redirect the output back to the menu. It can be done with single input of line of text , see attached. I just cannot see where or how the sample... (0 Replies)
Discussion started by: annacreek
0 Replies
log(n)								 Logging facility							    log(n)

NAME
log - Procedures to log messages of libraries and applications. SYNOPSIS
package require Tcl 8 package require log ?1.0.1? ::log::levels ::log::lv2longform level ::log::lv2color level ::log::lv2priority level ::log::lv2cmd level ::log::lv2channel level ::log::lvCompare level1 level2 ::log::lvSuppress level {suppress 1} ::log::lvSuppressLE level {suppress 1} ::log::lvIsSuppressed level ::log::lvCmd level cmd ::log::lvCmdForall cmd ::log::lvChannel level chan ::log::lvChannelForall chan ::log::lvColor level color ::log::lvColorForall color ::log::log level text ::log::logMsg text ::log::logError text ::log::Puts level text DESCRIPTION
The log package provides commands that allow libraries and applications to selectively log information about their internal operation and state. To use the package just execute package require log log::log notice "Some message" As can be seen above, each message given to the log facility is associated with a level determining the importance of the message. The user can then select which levels to log, what commands to use for the logging of each level and the channel to write the message to. In the following example the logging of all message with level debug is deactivated. package require log log::lvSupress debug log::log debug "Unseen message" ; # No output By default all messages associated with an error-level (emergency, alert, critical, and error) are written to stderr. Messages with any other level are written to stdout. In the following example the log module is reconfigured to write debug messages to stderr too. package require log log::lvChannel debug stderr log::log debug "Written to stderr" Each message level is also associated with a command to use when logging a message with that level. The behaviour above for example relies on the fact that all message levels use by default the standard command ::log::Puts to log any message. In the following example all mes- sages of level notice are given to the non-standard command toText for logging. This disables the channel setting for such messages, assum- ing that toText does not use it by itself. package require log log::lvCmd notice toText log::log notice "Handled by Another database maintained by this facility is a map from message levels to colors. The information in this database has no influence on the behaviour of the module. It is merely provided as a convenience and in anticipation of the usage of this facility in tk-based applica- tion which may want to colorize message logs. API
The following commands are available: ::log::levels Returns the names of all known levels, in alphabetical order. ::log::lv2longform level Converts any unique abbreviation of a level name to the full level name. ::log::lv2color level Converts any level name including unique abbreviations to the corresponding color. ::log::lv2priority level Converts any level name including unique abbreviations to the corresponding priority. ::log::lv2cmd level Converts any level name including unique abbreviations to the command prefix used to write messages with that level. ::log::lv2channel level Converts any level name including unique abbreviations to the channel used by ::log::Puts to write messages with that level. ::log::lvCompare level1 level2 Compares two levels (including unique abbreviations) with respect to their priority. This command can be used by the -command option of lsort. The result is one of -1, 0 or 1 or an error. A result of -1 signals that level1 is of less priority than level2. 0 signals that both levels have the same priority. 1 signals that level1 has higher priority than level2. ::log::lvSuppress level {suppress 1}] (Un)suppresses the output of messages having the specified level. Unique abbreviations for the level are allowed here too. ::log::lvSuppressLE level {suppress 1}] (Un)suppresses the output of messages having the specified level or one of lesser priority. Unique abbreviations for the level are allowed here too. ::log::lvIsSuppressed level Asks the package whether the specified level is currently suppressed. Unique abbreviations of level names are allowed. ::log::lvCmd level cmd Defines for the specified level with which command to write the messages having this level. Unique abbreviations of level names are allowed. The command is actually a command prefix and this facility will append 2 arguments before calling it, the level of the mes- sage and the message itself, in this order. ::log::lvCmdForall cmd Defines for all known levels with which command to write the messages having this level. The command is actually a command prefix and this facility will append 2 arguments before calling it, the level of the message and the message itself, in this order. ::log::lvChannel level chan Defines for the specified level into which channel ::log::Puts (the standard command) shall write the messages having this level. Unique abbreviations of level names are allowed. The command is actually a command prefix and this facility will append 2 arguments before calling it, the level of the message and the message itself, in this order. ::log::lvChannelForall chan Defines for all known levels with which which channel ::log::Puts (the standard command) shall write the messages having this level. The command is actually a command prefix and this facility will append 2 arguments before calling it, the level of the message and the message itself, in this order. ::log::lvColor level color Defines for the specified level the color to return for it in a call to ::log::lv2color. Unique abbreviations of level names are allowed. ::log::lvColorForall color Defines for all known levels the color to return for it in a call to ::log::lv2color. Unique abbreviations of level names are allowed. ::log::log level text Log a message according to the specifications for commands, channels and suppression. In other words: The command will do nothing if the specified level is suppressed. If it is not suppressed the actual logging is delegated to the specified command. If there is no command specified for the level the message won't be logged. The standard command ::log::Puts will write the message to the channel specified for the given level. If no channel is specified for the level the message won't be logged. Unique abbreviations of level names are allowed. Errors in the actual logging command are not caught, but propagated to the caller, as they may indicate miscon- figurations of the log facility or errors in the callers code itself. ::log::logMsg text Convenience wrapper around ::log::log. Equivalent to ::log::log info text. ::log::logError text Convenience wrapper around ::log::log. Equivalent to ::log::log error text. ::log::Puts level text The standard log command, it writes messages and their levels to user-specified channels. Assumes that the suppression checks were done by the caller. Expects full level names, abbreviations are not allowed. LEVELS
The package currently defines the following log levels, the level of highest importance listed first. o emergency o alert o critical o error o warning o notice o info o debug KEYWORDS
log, log level, message level, message log 1.0.1 log(n)
All times are GMT -4. The time now is 08:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy