subprocess call acts differently than command line call?

Rob Wolfe rw at smsnet.pl
Thu Jun 7 20:30:54 CEST 2007


Jim <jim.hefferon at gmail.com> writes:

> Hello,
>
> I need a program that will traverse a directory tree to ensure that
> there
> are unix-style line endings on every file in that tree that is a text
> file.
> To tell text files from others I want to use the unix "file" command
> (Python's "mimetypes" is not so good for me).  But I am stuck on
> something about getting that output, and I'd greatly appreciate any
> pointers.
>
> Both the command line "file" and the python libmagic binding give the
> same behavior, but I'll illustrate with "file".  It sometimes acts
> differently when run from the command line than when run using
> the subprocess module (with the same user).  For example, it
> sometimes
> gives output when run from the command line but no output when run as
> a subprocess.
>
> Below is a short program to demo.  (I use this on a test file tree
> that is at ftp://joshua.smcvt.edu/pub/hefferon/a.zip if anyone
> is interested.)

[...]

> I've put a transcript of what happens at the bottom of this message.
> One file (in the test tree it is "eqchange.txt") gives no output from
> the above program, but does give an output when I use "file" at the
> command line.

[...]

> -----transcript (edited to shorten)------------
> $ python test.py
> result:  acrotex/readme.txt: ASCII English text, with CRLF line
> terminators
>
> result:  acrotex/eq2db.ins: ASCII English text, with CRLF line
> terminators
>
> result:  acrotex/eqchange.txt:
>
> result:  acrotex/exerquiz.dtx: ISO-8859 English text, with CRLF line
> terminators
> result:  acrotex/doc: directory
>
> done
>
> $ file acrotex/eqchange.txt
> acrotex/eqchange.txt: ISO-8859 English text, with CRLF line

That's interesting. I've checked this eqchange.txt file from
your a.zip on my machine and the result is:

$ file acrotex/readme.txt
acrotex/readme.txt: ASCII English text, with CRLF line terminators
$ file acrotex/eqchange.txt
acrotex/eqchange.txt:
$ file acrotex/exerquiz.dtx
acrotex/exerquiz.dtx: ISO-8859 English text, with CRLF line terminators

$ file -v
file-4.17
magic file from /etc/magic:/usr/share/file/magic
$ uname -orvm
2.6.18-4-k7 #1 SMP Wed May 9 23:42:01 UTC 2007 i686 GNU/Linux

That's really strange. Have you got only *one* version of ``file``
program on your machine?

-- 
HTH,
Rob



More information about the Python-list mailing list