0

I may be missing something small, but is it possible to achieve this syntax in a POSIX (dash) compliant way:

$ ./myApp 2> stderr.txt 1> stdout.txt

I know in dash you cannot use >& but have to use 2>&1 but I do not want to do this. I have tons of data coming to stdout and I do not want to parse it to get my stderr. I feel like I am missing something extremely simple but I cannot put my finger on it...

Right now when I run the above command, I get only a few lines of my stdout (3) but it shows up in the stderr file and stdout is empty. I have also tried various ways of grouping it but still I have had no luck. Not sure what is going on...

UPDATE

This is the format of the actual command I am running so that you can see the full effect of what I am trying to accomplish:

$ LD_PRELOAD=/usr/lib/libtcmalloc.so /usr/bin/time -p myApp -c -f inputFile 2> stderr 1> stdout

This is where I mentioned that I tried multiple variants of groupings with (). Also, the executable myApp does not fork.

I thought that this command would work, but I have found otherwise:

$ LD_PRELOAD=/usr/lib/libtcmalloc.so /usr/bin/time -p (myApp -c -f inputFile) 2> stderr 1> stdout
Caleb
  • 870
  • 1
  • 10
  • 21
  • This syntax should work. Are you trying to do more than one command to the same file? (does your process ever fork?) – Random832 Sep 26 '11 at 22:23
  • @Random832 I updated the question to better describe what I am doing. Also, no forking action in my application. – Caleb Sep 26 '11 at 23:12
  • You may be getting some interference from the output of `time`. You might have to `time sh -c 'all your stuff including redirection'` (unless what you want to redirect _is_ the output of time) – Random832 Sep 27 '11 at 02:12
  • @Random832 Worked great! I can also redirect my time output after the '' so it all works out. – Caleb Sep 27 '11 at 15:25
  • @Random832 Since you answered it in the comments, how does it work from here? Is is typical that you should now post something so I can mark it as the answer? Or should I post the answer...? – Caleb Sep 27 '11 at 15:45

1 Answers1

0

Posting since I answered in the comments:

The syntax you posted is the correct syntax, but you may be getting some interference from the output of the time command. Try

time -p sh -c 'LD_PRELOAD=/usr/lib/libtcmalloc.so command >stdout.txt 2>stderr.txt'
Random832
  • 37,415
  • 3
  • 44
  • 63