#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25

    Python System calls


    I was wondering if there is a way have python let the shell execute something instead of python, like in perl or c where you can go

    Code:
    system("mkdir /blah");
    and it would make a directory for you, i have been researching i know perl has ways to make direcotrys that isn't platform dependant, that is nice, but there are thing i want to do that there os module can't do, besides the script i am trying to write is only going to be running on linux so it doesn't really matter.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    14
    Use os.system, commands.getoutput (if you care about just the text output), or one of the popen* modules if you want full control of stdin, stdout, and stderr.
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by Strike
    Use os.system, commands.getoutput (if you care about just the text output), or one of the popen* modules if you want full control of stdin, stdout, and stderr.
    Python 2.4 added a new module called subprocess to the standard library, which was designed as a replacement to the multiple popen* modules. If you have the chance I'd use this it is a big improvement:

    http://www.python.org/doc/2.4/whatsnew/node8.html
    http://www.python.org/doc/2.4/lib/module-subprocess.html

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25
    sweet, thanks very much. I have been wanting to go to python2.4 but i can't find a module for mysql that works with 2.4, so i have been stuck with python2.3 but the os.system works great thanks

IMN logo majestic logo threadwatch logo seochat tools logo