Sponsored Content
Top Forums UNIX for Dummies Questions & Answers multiple variables assignement (stdout/stderr outputs) Post 302448123 by anthalamus on Wednesday 25th of August 2010 10:19:51 AM
Old 08-25-2010
ha ha thanks agama, I guess i'll keep my temporary files then Smilie, they're not so bad after all!!
It's a pity though, i was hoping some kind of easy redirection like

Code:
ls not_a_file a_file >$OUT 2>$ERR # obviously does not actually work!

It wouldn't seem so hard to provide in shells nowadays, since the same can be achieved with a few commands using files. Anyway, I guess the question of whether it is actually useful or not is worth asking.

Anyway thanks to both of you!

EDIT: well I settled for:
Code:
COMMAND="ls not_a_file a_file"
OUT=`mktemp` && ERR=`mktemp` && eval "$COMMAND" 1>$OUT 2>$ERR; STDOUT=`cat $OUT` && STDERR=`cat $ERR` && rm $OUT $ERR
echo -e "STDOUT=$STDOUT\nSTDERR=$STDERR"

If something thinks of something much better, let me know!!

Last edited by anthalamus; 08-25-2010 at 02:40 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect stdout and stderr

How can I redirect and append stdout and stderr to a file when using cron? Here is my crontab file: */5 * * * * /dir/php /dir/process_fns.php >>& /dir/dump.txt Cron gives me an 'unexpected character found in line' when trying to add my crontab file. Regards, Zach Curtis POPULUS (8 Replies)
Discussion started by: zcurtis
8 Replies

2. Shell Programming and Scripting

precedence of stderr and stdout

#!/usr/bin/perl open(STDOUT, ">>$Textfile") open(STDERR, ">>$Textfile") print "program running\n"; $final = join("+", $initial,$final) #5 close (STDOUT); close (STDERR);Hi all, above is my perl code. Notice i have captured the stdout and stderr to the same textfile. my code is expected to... (1 Reply)
Discussion started by: new2ss
1 Replies

3. Shell Programming and Scripting

How to redirect stderr and stdout to a file

Hi friends I am facing one problem while redirecting the out of the stderr and stdout to a file let example my problem with a simple example I have a file (say test.sh)in which i run 2 command in the background ps -ef & ls & and now i am run this file and redirect the output to a file... (8 Replies)
Discussion started by: sushantnirwan
8 Replies

4. Shell Programming and Scripting

How to use tee with stdout and stderr?

I have been doing this: make xyz &> xyz.log &; tail -f xyz.log The problem with this is that you never can ge sure when "make xyz" is done. How can I pipe both stderr and stdout into tee so both stderr and stdout are copied both to the display and to the log file? Thanks, Siegfried (3 Replies)
Discussion started by: siegfried
3 Replies

5. Shell Programming and Scripting

sending stdout and stderr to a file

working on a c sell script I think I understand the concept of it, which is: filename >> file.txt (to appaend) or filename | tee -a file.txt (to append) The problem is that my shell script is used with several parameters, and these commands don't seem to work with just filename. They... (2 Replies)
Discussion started by: mistermojo
2 Replies

6. UNIX for Dummies Questions & Answers

Redirecting several outputs to /dev/stdout

I have an executable that, depending on its input, outputs to either one file or several. It usually prints nothing on screen. The usual way to call this program is to specify an input and output filenames, like this: ./executable.exe -i inputfile -o outputfileIt will then try to use the output... (1 Reply)
Discussion started by: aplaydoc
1 Replies

7. Red Hat

Make STDERR readable as STDOUT

Hi all. I am trying to use backticks in Perl to put STDERR into a string. The code is... $readkey_test = `perl -MTerm::ReadKey -e 1`; print $readkey_test; if ($readkey_test =~ m/]/) { print "ReadKey not installed...\n"; } else { print "ReadKey installed...\n"; } If it comes up... (3 Replies)
Discussion started by: austinharris43
3 Replies

8. Shell Programming and Scripting

stderr/stdout

Can somebody explain to me why the diff output is not going to stderr? Yet when I issue a diff from the command line the return code is -ne 1. I am guessing diff always writes to stdout??? Is there away I can force the difff to write to stderr USING THE CURRENT template. If possible, I... (5 Replies)
Discussion started by: BeefStu
5 Replies

9. Shell Programming and Scripting

stdout, stderr redirection

Hi all, can someone help me with the next redirection? i want to redirect the stdout+stderr of a command to the same file (this i can do by prog &> file) but in addition i want to redirect only the stderr to a different file. how can i do this please? (in BASH) thanks. (4 Replies)
Discussion started by: eee
4 Replies

10. Shell Programming and Scripting

[stdin / stdout] Strategies for redirecting outputs

Well.. let's say i need to write a pretty simple script. In my script i have 2 variables which can have value of 0 or 1. $VERBOSE $LOG I need to implement these cases: ($VERBOSE = 0 && $LOG = 0) => ONLY ERROR output (STDERR to console && STDOUT to /dev/null) ($VERBOSE = 1... (5 Replies)
Discussion started by: Marmz
5 Replies
SYSTEMD-CAT(1)							    systemd-cat 						    SYSTEMD-CAT(1)

NAME
systemd-cat - Connect a pipeline or program's output with the journal SYNOPSIS
systemd-cat [OPTIONS...] [COMMAND] [ARGUMENTS...] systemd-cat [OPTIONS...] DESCRIPTION
systemd-cat may be used to connect STDOUT and STDERR of a process with the journal, or as a filter tool in a shell pipeline to pass the output the previous pipeline element generates to the journal. If no parameter is passed systemd-command will write everything it reads from standard input (STDIN) to the journal. If parameters are passed they are executed as command line with standard output (STDOUT) and standard error output (STDERR) connected to the journal, so that all it writes is stored in the journal. OPTIONS
The following options are understood: --h, --help Prints a short help text and exits. --version Prints a short version string and exits. -t, --identifier= Specify a short string that is used to identify the logging tool. If not specified no identifying string is written to the journal. -p, --priority= Specify the default priority level for the logged messages. Pass one of emerg, alert, crit, err, warning, notice, info, debug, resp. a value between 0 and 7 (corresponding to the same named levels). These priority values are the same as defined by syslog(3). Defaults to info. Note that this simply controls the default, individual lines may be logged with different levels if they are prefixed accordingly. For details see --level-prefix= below. --level-prefix= Controls whether lines read are parsed for syslog priority level prefixes. If enabled (the default) a line prefixed with a priority prefix such as <5> is logged at priority 5 (notice), and similar for the other priority levels. Takes a boolean argument. EXIT STATUS
On success 0 is returned, a non-zero failure code otherwise. EXAMPLES
Example 1. Invoke a program This calls /bin/ls with STDOUT/STDERR connected to the journal: # systemd-cat ls Example 2. Usage in a shell pipeline This builds a shell pipeline also invoking /bin/ls and writes the output it generates to the journal: # ls | systemd-cat Even though the two examples have very similar effects the first is preferable since only one process is running at a time, and both STDOUT and STDERR are captured while in the second example only STDOUT is captured. SEE ALSO
systemd(1), systemctl(1), logger(1) AUTHOR
Lennart Poettering <lennart@poettering.net> Developer systemd 10/07/2013 SYSTEMD-CAT(1)
All times are GMT -4. The time now is 12:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy