I wrote the following code to determine which files a program writes to. I want to capture the filenames of course.
strace -f -t -e trace=file -p 8804 2>&1 | grep -oP "\"(.*)\".*O_WRONLY"
This outputs something like
/tmp/11111111.txt", O_WRONLY
The problem is I can't pipe the output of all this to any command
strace -f -t -e trace=file -p 8804 2>&1 | grep -oP "\"(.*)\".*O_WRONLY" | echo
# does not show anything
And also I can't save the output of all this for later use:
strace -f -t -e trace=file -p 8804 2>&1 | grep -oP "\"(.*)\".*O_WRONLY" > asd.out
# file is empty
Your help is appreciated. 🙂
Best Answer
You can write the output to a file (with
strace -o asd.out
) and then grep it:From strace manual: