1

In tcsh I want to redirect command line outputs to a file, but I still want to show them in the command line.

Did a little bit search that

./MyCommand.sh 2>&1 | tee /tmp/Output.txt

should do the job. But I got an error like:

Ambiguous output redirect
UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
Samo Jerom
  • 2,361
  • 7
  • 32
  • 38

3 Answers3

2

Use of 2>&1 to combine stderr and stdout works only in bash and sh. It does not for csh or tcsh. A work around is suggested at Redirect stdout to stderr in tcsh.

Community
  • 1
  • 1
R Sahu
  • 204,454
  • 14
  • 159
  • 270
0

In bash instead of 2>&1 I use |& Not sure how this plays out for tcsh, but this question isn't currently tagged for it and hoping this helps someone else.

According to this redirect stderr to stdout in c shell you can't do this in csh which tcsh extends which could be related

Community
  • 1
  • 1
UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
0

It isn't clear from the question if you want to redirect stdout only, or stdout and stderr.

Using | will redirect stdout to tee (which outputs it to a file and to terminal), leaving stderr untouched (so it only goes to terminal):

./MyCommand.sh | tee /tmp/Output.txt

Using |& will "merge" stdout and stderr, and tee will redirect both to file and to terminal:

./MyCommand.sh |& tee /tmp/Output.txt
shx2
  • 61,779
  • 13
  • 130
  • 153