469,632 Members | 1,730 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

Unix commands within Python code

Hi all,

I've just started to learn Python and I have a
question.

What is the syntax to embed Unix commands, or call
other programs within a Python script?

for example I would like to use a system chmod unix
command in the python script:

chmod 666 /tmp/filename

or call another script

/home/mailman/bin/list_members facultynews
${DIR}facultynew


I would appreciate if someone can send me the syntax,
or if its even possible.

--
Kory Wheatley

__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
Jul 18 '05 #1
3 2100
Basic is os.system(), but there are also
several os.popen#() calls depending on if you
need to get output or set environment before
execution.

There are also many os. commands that can
do this without shelling out to the Unix
shell, in particular:

os.chmod(path, mode)
FYI,
Larry Bates
Syscon, Inc.
"Kory Wheatley" <wh**************@yahoo.com> wrote in message
news:ma*************************************@pytho n.org...
Hi all,

I've just started to learn Python and I have a
question.

What is the syntax to embed Unix commands, or call
other programs within a Python script?

for example I would like to use a system chmod unix
command in the python script:

chmod 666 /tmp/filename

or call another script

/home/mailman/bin/list_members facultynews
${DIR}facultynew


I would appreciate if someone can send me the syntax,
or if its even possible.

--
Kory Wheatley

__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

Jul 18 '05 #2
On 2004-07-15, Kory Wheatley <wh**************@yahoo.com> wrote:
Hi all,

I've just started to learn Python and I have a
question.

What is the syntax to embed Unix commands, or call
other programs within a Python script?


http://docs.python.org/lib/os-process.html

http://docs.python.org/lib/module-popen2.html

http://docs.python.org/lib/module-commands.html
--
Grant Edwards grante Yow! YOW!! I'm in a very
at clever and adorable INSANE
visi.com ASYLUM!!
Jul 18 '05 #3
On Thu, 15 Jul 2004 13:01:17 -0500, Larry Bates wrote:
There are also many os. commands that can
do this without shelling out to the Unix
shell, in particular:

os.chmod(path, mode)


There's also the shutil module with some useful shell-like commands.

Jeremy

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Justin Johnson | last post: by
8 posts views Thread by Neale | last post: by
8 posts views Thread by Oli Schwarz | last post: by
2 posts views Thread by timdoyle05 | last post: by
5 posts views Thread by loial | last post: by
10 posts views Thread by blaine | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.