Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does wdiff not work with named pipes

Tags:

linux

bash

diff

How come I can do this in bash:

$ diff -u <(echo -e "line1\nline2") <(echo -e "line1\nline3")
--- /dev/fd/63  2009-03-30 09:49:07.527272646 +0100
+++ /dev/fd/62  2009-03-30 09:49:07.527272646 +0100
@@ -1,2 +1,2 @@
 line1
-line2
+line3

i.e. I can use named pipes / process substituion to get the diff of a small chunk of text. However when I try to do it with wdiff, the diff for words, not just lines, I get no useful output

wdiff <(echo -e "line1\nline2") <(echo -e "line1\nline3")
[--]{++}

UPDATE: looks like there's an existing ubuntu bug report for this: https://bugs.launchpad.net/ubuntu/+source/wdiff/+bug/160912

like image 359
Amandasaurus Avatar asked Mar 01 '23 21:03

Amandasaurus


1 Answers

An strace reveals that wdiff stats the files (probably to find out their size). Since named pipes report a size of 0 it probably assumes that both files are empty and therefore equal:

$ strace -efile wdiff -1 <(echo -e "line1\nline2") <(echo -e "line1\nline3")
execve("/usr/bin/wdiff", ["wdiff", "-1", "/dev/fd/63", "/dev/fd/62"], [/* 44 vars */]) = 0
[snip uninteresting stuff]
stat64("/dev/fd/63", {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
open("/dev/fd/63", O_RDONLY)            = 3
open("/tmp/wdiff.MzPXmH", O_RDWR|O_CREAT|O_EXCL, 0600) = 4
stat64("/dev/fd/62", {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
open("/dev/fd/62", O_RDONLY)            = 4
open("/tmp/wdiff.5nma9j", O_RDWR|O_CREAT|O_EXCL, 0600) = 5
--- SIGCHLD (Child exited) @ 0 (0) ---
unlink("/tmp/wdiff.MzPXmH")             = 0
unlink("/tmp/wdiff.5nma9j")             = 0
{++}Process 27699 detached

Edit: also note that bash may use /dev/fd-style filenames instead of named pipes if the kernel supports it (most recent ones do, the example above shows this), but the effect is pretty much the same.

like image 94
Joachim Sauer Avatar answered Mar 05 '23 16:03

Joachim Sauer