i guess that was too short tutorial well, here is an example from a live session on the interpreter.
[EMAIL PROTECTED] ~]# python Python 2.5.1 (r251:54863, Nov 23 2007, 16:16:53) [GCC 4.1.1 20070105 (Red Hat 4.1.1-51)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> cmd='ping -c 1 localhost' >>> import os >>> a=os.popen(cmd) >>> print a <open file 'ping -c 1 localhost', mode 'r' at 0xb7f1c728> >>> print a.read() PING serv.kontactel.loc (127.0.0.1) 56(84) bytes of data. 64 bytes from serv.kontactel.loc (127.0.0.1): icmp_seq=1 ttl=64 time=0.134ms --- serv.kontactel.loc ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.134/0.134/0.134/0.000 ms >>> i hope you can understand that now u have the output in a variable called "a" that you can parse & use as you wish. On Sun, Mar 16, 2008 at 7:12 PM, linuxian iandsd <[EMAIL PROTECTED]> wrote: > use os.popen("your cmd here") > > > On Sun, Mar 16, 2008 at 8:06 PM, Luke Paireepinart <[EMAIL PROTECTED]> > wrote: > > > shawn bright wrote: > > > Lo there all, > > > > > > I am needing to get a response back from a system command. > > > i can do this: > > > > > > os.system('mailq | wc -l") > > > > > > if i do this in the terminal mailq | wc -l , it will spit out a > > number. > > > How do i get that number as a python variable ? > > You need to use the subprocess module, specifically subprocess.Popen, to > > open an input pipe from the command so you can read() the data in. > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor