python 2.0 won't run scripts with \r\n line termination on RH7?

Tim Roberts timr at probo.com
Mon Feb 12 01:16:12 EST 2001


"Mike Carifio" <carifio.nospam at nospam.usys.com> wrote:
>
>I have a network of Linux and Windows machines. On a Windows box, I have
>several python scripts which I'd also like to run on the Linux machines.
>I've
>smbmounted the Windows share to see the scripts, but having been created
>on the Windows box, the line termination in those files is \r\n. When I try
>to execute the script, say 'start', I get:
>
>bash: ./start.py: No such file or directory
>
>When I "clean up" start.py with tr - tr -d '\r' < start.py > reallystart.py,
>it runs. So it seems like python 2 can't compensate for wierd Windows line
>terminators. Any workarounds, other than 'tr'? Pl. advise. Tx.

Your diagnosis is incorrect, as you should have seen by the error message.
Python handles either line terminator on either operating system.  The
problem here is not Pyhton, it is the shell.  The first line of your script
probably says:
  #! /usr/bin/python

When bash tries to figure out how to run this file, it looks at the first
two characters.  When it finds #!, it assumes the next token on the line is
the name of a file to be executed to handle the script.  In your case, it
reads the file name as /usr/bin/python\r, and there is no such file or
directory.  Hence, the error.

The script will run correctly if you say:
  python start.py

Admittedly, this is not ideal.  You also might be able to work around this
by adding something to the #! line, but this might require experimentation.
Adding a single space might be an interesting option.
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list