ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have two python script files that do the same thing. One was created on a different computer and bought over(Windows, but I doubt that's it). One I created to test why the first one wasn't working correctly. The contents of the program aren't the problem because its the same code. If it means any thing I am currently running Slackware 13.37 64bit
Both scripts work correctly when run correctly when run like this.
Code:
python test.py
The problem occurs when I run the programs through the operating system. The programing I created recently works fine while the one I brought over doesn't.
Code:
$ ./test.py
Hello World!
$ ./test2.py
bash: ./test2.py: /usr/bin/python^M: bad interpreter: No such file or directory
One last thing. The files are of different file types. This is probable the problem but Google returned nothing for me. If you need any more information I'll try to post it as fast as possible. Thanks for the help.
Code:
$ file test.py
test.py: Python script text executable
$ file test2.py
test2.py: a /usr/bin/python\015 script text executable
That did it. How come the program worked fine in when run with python test.py but not ./test.py? Also without the carriage returns will the program still function in a windows environment. Thanks for the help.
Distribution: BeOS, BSD, Caldera, CTOS, Debian, LFS, Mac, Mandrake, Red Hat, Slackware, Solaris, SuSE
Posts: 1,761
Rep:
Probably because the former method was a file input to the Python interpreter while the later was not.
Another common problem is scripts containing a carriage return character immediately after the shebang, perhaps as a result of being edited on a system that uses DOS line breaks, such as Microsoft Windows. Some systems interpret the carriage return character as part of the interpreter command, resulting in an error message. http://en.wikipedia.org/wiki/Shebang_%28Unix%29 http://www.itforeveryone.co.uk/shellProgramming.html
Not sure about running the removed CRs script back in Windows. Maybe open the script in Notepad and save the file. I don't take scripts back to Windows.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.