How to redirect the output to two different files when two command are involved simultaneously?

StackOverflow https://stackoverflow.com/questions/13232889

  •  27-11-2021
  •  | 
  •  

سؤال

I am using perf tool to analyze sort utility . I gave following command.

perf stat -x, ../bin/sort data >/dev/null 2>perf_data

I want to redirect the output of sort to /dev/null and output of perf to perf_data file.

How can I Do this ?

هل كانت مفيدة؟

المحلول

Actually you can put it in parenthesis. Following command has worked for me.

(perf stat -x, ../bin/sort data >/dev/null) 2>perfoutput.txt

نصائح أخرى

The "perf" command has an option to redirect output to a file directly using -o option. In your case this will be

perf stat -o perfoutput.dat -x, ../bin/sort data >/dev/null

Depending on the way how perf runs the program, simply quoting the arguments may be enough:

perf stat -x, '../bin/sort data >/dev/null' 2>perf_data
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top