grep strace 出力が難しくなります。

grep strace 出力が難しくなります。

プログラムがどのファイルに書き込むかを決定するために、次のコードを書きました。もちろん、ファイル名をキャプチャしたいです。

strace -f -t -e trace=file -p 8804 2>&1 | grep -oP "\"(.*)\".*O_WRONLY"

この出力は次のようになります。

/tmp/11111111.txt", O_WRONLY

問題は、これらすべての出力をどのコマンドにもパイプできないことです。

strace -f -t -e trace=file -p 8804 2>&1 | grep -oP "\"(.*)\".*O_WRONLY" | echo
# does not show anything

また、後で使用するためにこれらの結果をすべて保存することはできません。

strace -f -t -e trace=file -p 8804 2>&1 | grep -oP "\"(.*)\".*O_WRONLY" > asd.out
# file is empty

ご協力ありがとうございます。 :)

ベストアンサー1

出力をファイルに書き込んstrace -o asd.outでから ( を使用して) grep できます。

strace マニュアルから:

-o filename Write  the  trace  output to the file filename rather than 
to stderr.  Use filename.pid if -ff is used. If the argument begins with
`|' or with `!' then the rest of the argument is treated as a command
and all output is piped to it. This is convenient for piping the
debugging output to a program without affecting the redirections of 
executed programs.

おすすめ記事