473,508 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2248
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6267
by: Justin Johnson | last post by:
I have a unix id that has group1 for a primary group, and group2, group3, and group4 for supplementary groups. I'd like to change my primary group before running certain commands. So sometimes I...
8
2737
by: Neale | last post by:
In a python program, I want to do a Unix directory list and then append selected files to each other which, as you know, is just "cat filename2 >> filename1." How do I escape into the shell and...
8
5248
by: Oli Schwarz | last post by:
Hello, how can I read out the uptime of a unix system in python (Linux and *BSD). I have not found a uptime-function in the Library. Regards Oli
4
4053
by: rkoida | last post by:
Hello evryone I am a newbie to python. I have a makefile which i can compile in UNIX/LINUX, But i I am planning to write a python script which actually does what my MAKEFILE does. The make file...
2
2986
by: timdoyle05 | last post by:
Hi, I have a question relating to how Unix commands can be issued from Python programs. Im am currently writing a large test script in python and I need this script to call three other separate...
4
2349
by: Michael | last post by:
Hi, I'm having difficulty finding any previous discussion on this -- I keep finding people either having problems calling os.exec(lepev), or with using python's exec statement. Neither of...
5
4856
by: loial | last post by:
How can I delete hidden files on unix with python, i.e I want to do equivalent of rm .lock*
10
1969
by: blaine | last post by:
Hey everyone, So I've got a quick query for advice. We have an embedded device in which we are displaying to an LCD device that sits at /dev/screen. This device is not readily available all...
2
2303
by: sixtyfootersdude | last post by:
Hey all! Just doing some tinkering with python. I am running mac os x and I am wondering how I can call unix commands from python. In C I think I would use a fork, although it has been...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.