Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect output from csh script 1

Status
Not open for further replies.

chorgan

Programmer
Jun 19, 2001
5
IE
Basically my script contains one very long command to start an application , the problem is it is generating a warning and i dont want that warning to be displayed how do i redirect the o/p of the command to a file and not to the screen so the user wont see it?
 
To redirect to standard output:
command > file
To redirect to standard output and standard error:
command >& file
 
command >& outputfile

(note the & after the >, with no space between them. This redirects both the standard output & standard errors to outputfile) TandA

Day by day, the penguins steal my sanity.
 
I have this:

command >& myfile.txt

but it is giving me an error - "Bad Number"
and referencing the file name I used do i need to declare the file name as a variable ?
I tried putting it in "" but got the same error

There is somethiung basic and blatantly obvious that I am missing, very possible as Ive never coded a Cshell b4 and only a little dabble of awk/perl/bourne shell
 
Hi,
Maybe redirecting the output from the command to eliminate the warning isn't what is needed. Maybe you need to figure out why the warning is coming out and see if you can eliminate it from your script.

For example, if command is something like.....

ls -l *.q | grep joke
( poor example but illustrates point)

and the LS would report 'No Match' which comes out through STDERR. You can correct this by also redirecting STDERR to the GREP which will throw it away because it doesn't match the grep pattern.

ls -l *.c |& grep joke


Adding to the posts about

Most UNIX's allow you to specify all output goes to the bit bucket. ( /dev/null )

command ... >&! /dev/null

> means redirect stdout
& means redirect Stderr
! means delete the file if it already exists.

There is no way just to redirect STDERR, so if you want the stdout to come out to the user but not the stderr you need to do something like....

( command > /tmp/out.$$ ) >&! /dev/null
cat /tmp/out.$$
rm -f /tmp/out.$$

This will redirect stdout to the /tmp/out.$$ file and then display it to the user and the stderr goes to the bit bucket.

hope this helps.

 
Thanks, but still cant redirect my errors as I need the application (STDOUT) to start anyway, I have a patch which might get rid of the warning - I'll have to try that instead
 
Hi,
Then for your output file figure out which tty device you are using for STDOUT and make that your output file.

set t = `tty`
( command >! $t ) >&! /dev/null

Again this will make the STDOUT go to the TTY device ( which should be the screen ) and STDERR will go to the bit bucket.



 
You can redirect STDERR only by using

command 2> errors.log

which is derived from the construct

command > logfile.log 2>&1

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top