Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've written a script and I want to direct the console output to a file, so I use this command:

~/simplesim-3.0/sim-cache -cache:dl1 dl1:1:64:2048:f -cache:il1 il1:1:64:2048:f \
-cache:il2 dl2 -cache:dl2 dl2:1:64:16384:f -tlb:itlb none \
-tlb:dtlb none cc1.alpha -O 1stmt.i 2>&1 | tee mkdir  ./cc.txt

The part upto "1stmt.i" is a command for a simulation tool (Simplescalar). This works fine though. However when I try the same for a different command:

~/simplesim-3.0/sim-cache -cache:dl1 dl1:512:64:2:f -cache:il1 il1:512:64:2:f \
-cache:il2 dl2 -cache:dl2 dl2:16384:64:1:f -tlb:itlb none -tlb:dtlb none \
anagram.alpha words < anagram.in > OUT 2>&1 | tee mkdir  ./cc3.txt

The file (cc3.txt) is an empty file. I don't understand why is the redirection not happening.

share|improve this question

migrated from programmers.stackexchange.com Oct 14 '14 at 12:14

This question came from our site for professional programmers interested in conceptual questions about software development.

    
Are you sure there should be a mkdir after tee? –  Vikyboss Oct 14 '14 at 3:55
    
I need the mkdir because the file may or may not be present when this command runs. –  user3224083 Oct 14 '14 at 5:47

1 Answer 1

up vote 1 down vote accepted

You are redirecting your outputs both STDOUT(> OUT) and STDERR(2>&1, means redirect errors to where STDOUT points to) to a file called OUT.

Since both STDOUT and STDERR gets written to a file called OUT, nothing gets piped to the tee command. So your cc3.txt file is empty.

share|improve this answer
    
Ok. How can I have the STDOUT written to both OUT and cc3.txt ? I tried > OUT | > cc3.txt but that did not help. –  user3224083 Oct 14 '14 at 3:39
    
You are again redirecting the STDOUT to OUT(> OUT) before the pipe("|"). If you want both to print the output as redirect the outputs to two files, I would suggest copy command(cp) to create the duplicate file. –  Vikyboss Oct 14 '14 at 3:44
    
If you want to print the output as well redirect the outputs to two files, I would suggest tee the output to cc3.txt then copy cc3.txt and create a file called OUT. Something like this should work "... 2>&1 | tee ./cc3.txt; cp ./cc3.txt OUT" –  Vikyboss Oct 14 '14 at 3:54
    
You want ... 2>&1 | tee OUT | tee cc3.txt –  talkloud Oct 14 '14 at 12:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.