Standard error and output redirection

Standard error and output redirection

Post by ragnar5 » Sun, 16 Jan 2000 04:00:00



    Hello,

    After redirecting standard error and output to a file such as
2>/dev/null, how do you reassign it back to where it was?

    Thanks,

 
 
 

Standard error and output redirection

Post by Douglas Wils » Sun, 16 Jan 2000 04:00:00



>    After redirecting standard error and output to a file such as
>2>/dev/null, how do you reassign it back to where it was?

You didn't say how you redirected it, if you used exec, then you
need to 'save' where the file descriptors were pointing:

# Save stdin
exec 3>&1
exec 4>&2

# Redirect stdin, stderr
exec 1>/dev/null
exec 2>/dev/null

# Output of command goes to /dev/null
command

#Restore stdin, stderr
exec 1>&3
exec 2>&4

Is this a FAQ yet, I'll have to check, if its not it should be.

HTH,
Douglas Wilson