executing system calls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • earthdirt
    New Member
    • Mar 2008
    • 3

    executing system calls

    Python Newbie running Mandriva Linux.

    I want to do a system call from a python program. Mandriva has a package manager command called urpmi. If I wanted it to install a rpm I would say on the command line "urpmi rpmname". How can execute this command from my python program?

    I found 'subprocess' in the python docs, imported it into IDLE, but I can't seem to make it's example work.

    So, if I wanted to do the "urpmi rpmname" command or "urpmi --auto-update" which would update my system, what should the python statement look like in my python code?

    Thanks!
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    Use os.system(). It takes a string input that is the same thing you would normally type on the command line to do something, for example, to do ls,
    [CODE=python]
    import os
    os.system('ls')
    [/CODE]

    If those commands require root, as their equivalents do under Ubuntu, there's a bit more work needed, but it's still doable. I think.

    Comment

    Working...