You are not logged in.
Pages: 1
I am trying to get args passed in bash to
$1 etc ...
wondered if I can fire a system command from python?
errr
import os
os.system('free')
wondered if popen was a better option
ok ok I am looking honest lol
Mr Green
Offline
hey mister green,
take a look at the commands module.
small example :
import commands
program = "ls"
arg = commands.mkarg("-all") # usefull adding space ahead
output = commands.getoutput(program + arg)
Offline
os.popen is for piping.
I prefer subprocess personally. I think they're pushing people to use it over command() os.system() os.spawnvp() etc, etc. There is also many conversion examples in the help.
from subprocess import Popen
retcode = Popen('mr green shell command', shell=True).wait()
if retcode != 0:
print 'mr greens program failed. Damninations.'
Offline
does Subprocess fork() the current process like the name suggests ?
Depends maybe on the usage, the reason I like commands.getouput is that it's a very convenient way to retrieve the result of a command in a list of lines. I'm not sure popen does the same
Offline
I have heard of popen ... but not Popen
Emmm looks like what I need fire a bash command then exit...
managed to get 3 scripts down to 2 but I have been calling a bash script from python messy.....
see how it goes thanks
Mr Green
Offline
Technically you should use subprocess in place of popen - it is supposed to be the most modern one
Offline
well its just that I had never heard of it. .. so I'm going to give it go....
works fine... only I cannot use it in openbox menu
execute calls command ... so ... emm will have think
ie when you click/select item in menu I want command to run
Mr Green
Offline
right I have managed to get three scripts down to two ...
What I need is to have python script pipe output of bash commands to /tmp/cmd
confused about if I should use popen or os.system ... writing to file should not bee a problem just need to get info
/me thinks
Mr Green
Offline
def foo(x, f):
x = open(x)
l = x.write()
x.close()
return l
not sure about this need to get output from command into /tmp/cmd
reading command I use os.popen
getting in over my head lol
Mr Green
Offline
Pages: 1