You are not logged in.

#1 2012-04-04 20:04:45

tungsten
Member
Registered: 2012-02-22
Posts: 14

Colordiff ignoring standard input.

EDIT: The issue is with colordiff, actually, since I have an alias.

I was trying to use diff in a simple script that compares a file with a program's output.
Something wasn't quite right, so I tried:

[pedro@fenix ~][pedro@fenix ~]$ echo "herp" > derp
[pedro@fenix ~]$ diff derp derp
[pedro@fenix ~]$ cat derp | diff derp -
1d0
< herp
[pedro@fenix ~]$ cat derp | diff - derp
0a1
> herp
[pedro@fenix ~]$ cat derp | md5sum
882be39277c094b21e80bb8938d633b7  -
[pedro@fenix ~]$ md5sum derp
882be39277c094b21e80bb8938d633b7  derp
[pedro@fenix ~]$ diff -v
diff (GNU diffutils) 3.2
Copyright © 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Eggert, Mike Haertel, David Hayes,
Richard Stallman, and Len Tower.
[pedro@fenix ~]$ 

Tried the same thing on a different computer with Arch, same results.
Then I tried it on a Fedora box, and got the expected output:

[ra137264@xaveco ~]$ echo "herp" > derp
[ra137264@xaveco ~]$ diff derp derp
[ra137264@xaveco ~]$ cat derp | diff - derp
[ra137264@xaveco ~]$ cat derp | diff derp -
[ra137264@xaveco ~]$ cat derp | md5sum
882be39277c094b21e80bb8938d633b7  -
[ra137264@xaveco ~]$ md5sum derp
882be39277c094b21e80bb8938d633b7  derp
[ra137264@xaveco ~]$ diff -v
diff (GNU diffutils) 3.2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Eggert, Mike Haertel, David Hayes,
Richard Stallman, and Len Tower.
[ra137264@xaveco ~]$ 

What is the reasonable explanation to this behavior?

Last edited by tungsten (2012-04-04 20:17:14)

Offline

#2 2012-04-04 20:12:59

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: Colordiff ignoring standard input.

$ echo herp > derp
$ diff derp derp
$ cat derp
herp
$ cat derp | diff - derp
$ cat derp | diff derp -
$

Works for me.

Offline

#3 2012-04-04 20:16:00

tungsten
Member
Registered: 2012-02-22
Posts: 14

Re: Colordiff ignoring standard input.

I just realized I have colordiff and "alias diff='colordiff'" in my .bashrc. The issue is with colordiff only.

Offline

#4 2012-04-04 20:21:10

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Colordiff ignoring standard input.

Note that if you want to diff with the output of a command, a temporary file is unnecessary. Use process substitution:

$ diff <(seq 2 10) <(seq 1 9)
0a1
> 1
9d9
< 10

Offline

#5 2012-04-04 20:30:14

tungsten
Member
Registered: 2012-02-22
Posts: 14

Re: Colordiff ignoring standard input.

Procyon wrote:

Note that if you want to diff with the output of a command, a temporary file is unnecessary. Use process substitution:

$ diff <(seq 2 10) <(seq 1 9)
0a1
> 1
9d9
< 10

The file I'm comparing with isn't generated by me, it's the expected output of a program I'm supposed to code, given some input:

[pedro@fenix lab05]$ for f in {1..4}; do ./lab05 < arq$f.in | "diff" arq$f.res -; done
[pedro@fenix lab05]$ for f in {1..4}; do ./lab05 < arq$f.in | colordiff arq$f.res -; done
1d0
< 6 6 6 6 6
1d0
< 9 3 0 8 6 4 2 6 5 3 0 8 7 0 8 6 4 2 0
1d0
< 4 5 3 9 1 5 9 9 5 5 5 4 6 0 3 2 9 9
1d0
< 1 1 4 7 7 6 3 6 5 3 5 6 6 0 1 3 0 6 4 1
[pedro@fenix lab05]$ for f in {1..4}; do colordiff arq$f.res <(./lab05 < arq$f.in) ; done
[pedro@fenix lab05]$

So why does it work with that but not with the pipe I'm used to?

Last edited by tungsten (2012-04-04 20:41:22)

Offline

#6 2012-04-04 20:49:19

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Colordiff ignoring standard input.

tungsten wrote:

So why does it work with that but not with the pipe I'm used to?

Pipes and process substitution operate quite differently.  I guess it comes down to a bug in the colordiff script.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

Board footer

Powered by FluxBB