December 1st, 2004, 10:21 AM
How do I us popen2 module?
Well I have bin asking my self how to us the popen2 modules to open the cmd and to do something for example.
Could you please help.
December 1st, 2004, 03:53 PM
You don't really need to open the command prompt to do something (and I don't think you could see it if you did run it from os.popen) - you can just do something and read the results directly;
source = os.popen("dir c:\\")
To use popen2 to read and write... I don't know - what are you trying to run?
December 1st, 2004, 05:48 PM
Python has a rich but confusing number of variations of popen. However if you install Python 2.4 they have a new 'subprocess' module that should simplify the code needed.
However if you want to interact with the program instead of just run it and capture the output, then you will need to use some variation of expect - google for 'pexpect' for a pure python implementation.
Dave - The Developers' Coach
December 2nd, 2004, 04:42 AM
As has been said - many ways to skin the cat but to answer your question ...
#example of popen2 picking up IP addresses
procout,procin = popen2.popen2("ipconfig")
response = procout.readlines()
for n in response:
if "IP Address" in n:
December 2nd, 2004, 09:03 AM
thanks man ill try it
thanks it works but how would u make it send it to someone for example a email and could it also show u the host name
December 4th, 2004, 10:54 AM
could someone tell me how i would get it the ip adress sent to me or whatever i get from that place like the platform and version to my email for example