LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-17-2011, 05:19 AM   #1
archanadubbaka
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Rep: Reputation: Disabled
How to execute the python script using the cmd line in linux...?


Hi LQ Members,

I am completely new to python and executing the scripts using the cmd line is creating a prob to me. Could please any 1 help me out.

I write the code and save it as prog1.py using gedit of ubuntu.

Now i try to execute it as:
$ chmod +x prog1.py
$python prog1.py

but all the time it throws me a syntax invalid error.

Please help me regarding this.

Thanks & Regards,
Archana
 
Old 10-17-2011, 05:41 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Showing us the actual error would be of help.
 
1 members found this post helpful.
Old 10-17-2011, 07:06 AM   #3
archanadubbaka
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi Grail,

The following is the error it displays when I try to execute the code:-

# /usr/bin/python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> chmod +x apple.py
File "<stdin>", line 1
chmod +x apple.py
^
SyntaxError: invalid syntax

Please help me sort this problem.

Thanks & Regards,
Archana.
 
Old 10-17-2011, 07:09 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
YOu have to launch those commands in Bash, not the Python interpreter. Try them again, without launching Python before.
 
1 members found this post helpful.
Old 10-17-2011, 07:28 AM   #5
archanadubbaka
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for your guidance and solution TobiSGD!

Regards,
Archana
 
Old 10-17-2011, 08:09 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Remember to mark as SOLVED once you have a solution.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Read a line of C comamnd and execute in Shell Script mark.cooray Linux - Newbie 6 11-11-2010 10:22 PM
crontab doesn't execute python script right msegmx Linux - Newbie 13 05-04-2009 10:29 AM
crontab is failed to execute my python script tcyeo Linux - Newbie 4 04-06-2009 12:14 AM
Multithreaded python script calls the COMMAND LINE jCash Linux - Newbie 1 12-08-2006 09:09 AM
How to execute a command line in a shell script orgazmo Programming 5 05-09-2005 10:16 AM


All times are GMT -5. The time now is 07:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration