My program generates two strings and I want them compared by the external diff tool. The diff tool accepts only files/directories as arguments. That’s diff file1 file2 works perfectly but diff "hello" "world" doesn’t work. Is there a way to pass my strings directly to diff without creating any temporary files? Thanks.
My program generates two strings and I want them compared by the external diff
Share
On the shell, you can use temporary pipes.
Use the backticks operator or any other method to execute the command in php. For details on executing commands, see the manual: http://www.php.net/manual/en/ref.exec.php
Make sure, you properly escape the strings.
EDIT: This feature is called temporary pipes. So the shell translates it to a file descriptor.
For a detailed explanation see http://www.linuxjournal.com/article/2156?page=0,1