Error Starting Python Script(bash Problem)


Recommended Posts

I am going mad trying to figure this out. I have a python script that runs fine if I start it like this

python /home/shane/bin/gettorrent

but if I run it directly like this

/home/shane/bin/gettorrent

I get the following error

shane@mainbox ~ $ /home/shane/bin/gettorrent
: No such file or directory

the file is exectuable

shane@mainbox ~ $ ls -l /home/shane/bin/gettorrent
-rwxr-xr-x 1 shane users 6556 Jan 9 21:35 /home/shane/bin/gettorrent

and it starts with this

shane@mainbox ~ $ cat /home/shane/bin/gettorrent
#!/usr/bin/env python
#
# gettorrent-5b
#
import urllib, urllib2, cPickle, os, sys

I am sure I am doing something really dumb, but can't seem to see it.

Link to post
Share on other sites

The problem was I origianlly wrote this using drpython on windows. So drpython added both a carriage return and a newline. So to run it on my linux system I needed to remove the "\r" carriage return.

I was reading on the differnt line endings differnt OSs use. they say unix uses a \n. Is that a property of bash that requires this?

Edited by shanenin
Link to post
Share on other sites

its the diffrece between msdos text file type and unix type.. /r/n for dos /n for unix

you can do this

dos2unix filename filename

this should fix it.. you may hve to install dos2unix

gentoo has two program dos2unix or hd2u (hanny's dos 2 unix)

the first will need to be unmasked but I know it works..

Edited by iccaros
Link to post
Share on other sites
I was reading on the differnt line endings differnt OSs use. they say unix uses a \n. Is that a property of bash that requires this?

POSIX requirement and Unix tradition. Text lines are terminated by ASCII LFs (0x0a). (Fun project: A sequence of characters that isn't terminated with a newline isn't a line of text according to POSIX. Count how many text files you have that technically aren't text files.). On the other hand CRLF pairs are not uncommon in display and network protocols.

Edited by jcl
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...