tree /some/directory | print.sh
Is there any way for print.sh to know that "tree -f /some/directory" was called, without trying to parse
In general this information cannot be obtained.
Whatever it is you're trying to, you need to look for a solution in a different solution. This is probably going to involve having the script that's calling the pipe do the logging the first command.