Unix commands within Python code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kory Wheatley

    Unix commands within Python code

    Hi all,

    I've just started to learn Python and I have a
    question.

    What is the syntax to embed Unix commands, or call
    other programs within a Python script?

    for example I would like to use a system chmod unix
    command in the python script:

    chmod 666 /tmp/filename

    or call another script

    /home/mailman/bin/list_members facultynews[color=blue]
    >${DIR}facultyn ew[/color]

    I would appreciate if someone can send me the syntax,
    or if its even possible.

    --
    Kory Wheatley



    _______________ _______________ ____
    Do you Yahoo!?
    New and Improved Yahoo! Mail - Send 10MB messages!
    Shop the best deals at Yahoo! Shopping! Discover discounts on a wide range of products, from electronics to fashion, and enjoy exclusive offers. Save big with top deals today!

  • Larry Bates

    #2
    Re: Unix commands within Python code

    Basic is os.system(), but there are also
    several os.popen#() calls depending on if you
    need to get output or set environment before
    execution.

    There are also many os. commands that can
    do this without shelling out to the Unix
    shell, in particular:

    os.chmod(path, mode)


    FYI,
    Larry Bates
    Syscon, Inc.


    "Kory Wheatley" <wheakoryperson al@yahoo.com> wrote in message
    news:mailman.44 7.1089914219.51 35.python-list@python.org ...[color=blue]
    > Hi all,
    >
    > I've just started to learn Python and I have a
    > question.
    >
    > What is the syntax to embed Unix commands, or call
    > other programs within a Python script?
    >
    > for example I would like to use a system chmod unix
    > command in the python script:
    >
    > chmod 666 /tmp/filename
    >
    > or call another script
    >
    > /home/mailman/bin/list_members facultynews[color=green]
    > >${DIR}facultyn ew[/color]
    >
    > I would appreciate if someone can send me the syntax,
    > or if its even possible.
    >
    > --
    > Kory Wheatley
    >
    >
    >
    > _______________ _______________ ____
    > Do you Yahoo!?
    > New and Improved Yahoo! Mail - Send 10MB messages!
    > http://promotions.yahoo.com/new_mail[/color]


    Comment

    • Grant Edwards

      #3
      Re: Unix commands within Python code

      On 2004-07-15, Kory Wheatley <wheakoryperson al@yahoo.com> wrote:[color=blue]
      > Hi all,
      >
      > I've just started to learn Python and I have a
      > question.
      >
      > What is the syntax to embed Unix commands, or call
      > other programs within a Python script?[/color]








      --
      Grant Edwards grante Yow! YOW!! I'm in a very
      at clever and adorable INSANE
      visi.com ASYLUM!!

      Comment

      • Jeremy Sanders

        #4
        Re: Unix commands within Python code

        On Thu, 15 Jul 2004 13:01:17 -0500, Larry Bates wrote:
        [color=blue]
        > There are also many os. commands that can
        > do this without shelling out to the Unix
        > shell, in particular:
        >
        > os.chmod(path, mode)[/color]

        There's also the shutil module with some useful shell-like commands.

        Jeremy

        Comment

        Working...