|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
running bash command
hey people
total python noob here how can i run a bash command from within a python script - like perl does with the `ls` backticks? |
|
#2
|
||||
|
||||
|
There are two ways you can do this on *nix... the 'commands' module is by far the best, the disadvantage being that its only available on *nix!
http://www.python.org/doc/2.3.3/lib...e-commands.html Your other option is the system() function from the os module i.e. Code:
pseudocode
import os
os.system('command')
http://www.python.org/doc/2.3.3/lib/os-process.html Mark. |
|
#3
|
|||
|
|||
|
os.system won't help if you want the output. commands.getoutput is the easiest way, but there are also the popen* modules to allow advanced control of all the possible file-handle combinations involved with process invocation and management.
However, for specifically getting directory contents, use os.listdir. |
|
#4
|
|||
|
|||
|
thanks guys - you rock!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > running bash command |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|