Exeucte a system command in python script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ken.carlino@gmail.com

    #1

    Exeucte a system command in python script

    Hi,

    I would like to execute a shell command like this in python:
    cmd = 'ant release -Dbuild=build_pr oxyonly -Drev=5.1.130f
    -Dprops=\"-MIDP20_LARGE;PU SH_FEATURE=fals e;MIDlet-Version=5.0;ver sion=5.0;MIDlet-Icon=midicon15x 15.png;-FOUR_WAY_NAV_FE ATURE\"
    -DThree_Branding =true'

    Which of the execl command described here should I use?


    Thank you for any help.

  • Robert Kern

    #2
    Re: Exeucte a system command in python script

    ken.carlino@gma il.com wrote:[color=blue]
    > Hi,
    >
    > I would like to execute a shell command like this in python:
    > cmd = 'ant release -Dbuild=build_pr oxyonly -Drev=5.1.130f
    > -Dprops=\"-MIDP20_LARGE;PU SH_FEATURE=fals e;MIDlet-Version=5.0;ver sion=5.0;MIDlet-Icon=midicon15x 15.png;-FOUR_WAY_NAV_FE ATURE\"
    > -DThree_Branding =true'
    >
    > Which of the execl command described here should I use?
    > http://pydoc.org/1.6/os.html[/color]

    None. You should use the subprocess module in 2.4 (I really do hope that you're
    not using 1.6).

    Source code: Lib/subprocess.py The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace seve...


    It also works in Pythons as old as 2.2, but you'll have to install it
    separately. The website for the separate release is down at the moment, but when
    it comes back up:



    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco

    Comment

    • ken.carlino@gmail.com

      #3
      Re: Exeucte a system command in python script

      Thanks I get this error 'NameError: global name 'call' is not defined"

      I already import 'subprocess'.

      Can you pleaes tell me what am I missing?

      Robert Kern wrote:[color=blue]
      > ken.carlino@gma il.com wrote:[color=green]
      > > Hi,
      > >
      > > I would like to execute a shell command like this in python:
      > > cmd = 'ant release -Dbuild=build_pr oxyonly -Drev=5.1.130f
      > > -Dprops=\"-MIDP20_LARGE;PU SH_FEATURE=fals e;MIDlet-Version=5.0;ver sion=5.0;MIDlet-Icon=midicon15x 15.png;-FOUR_WAY_NAV_FE ATURE\"
      > > -DThree_Branding =true'
      > >
      > > Which of the execl command described here should I use?
      > > http://pydoc.org/1.6/os.html[/color]
      >
      > None. You should use the subprocess module in 2.4 (I really do hope that you're
      > not using 1.6).
      >
      > http://docs.python.org/lib/module-subprocess.html
      >
      > It also works in Pythons as old as 2.2, but you'll have to install it
      > separately. The website for the separate release is down at the moment, but when
      > it comes back up:
      >
      > http://www.lysator.liu.se/~astrand/popen5/
      >
      > --
      > Robert Kern
      >
      > "I have come to believe that the whole world is an enigma, a harmless enigma
      > that is made terrible by our own mad attempt to interpret it as though it had
      > an underlying truth."
      > -- Umberto Eco[/color]

      Comment

      • Robert Kern

        #4
        Re: Exeucte a system command in python script

        ken.carlino@gma il.com wrote:[color=blue]
        > Thanks I get this error 'NameError: global name 'call' is not defined"
        >
        > I already import 'subprocess'.
        >
        > Can you pleaes tell me what am I missing?[/color]

        Almost certainly you are doing something like this:

        import subprocess
        call(['something', 'or', 'other'])

        You need to learn how imports work in Python. Please read the tutorial:

        Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax an...


        --
        Robert Kern

        "I have come to believe that the whole world is an enigma, a harmless enigma
        that is made terrible by our own mad attempt to interpret it as though it had
        an underlying truth."
        -- Umberto Eco

        Comment

        • ken.carlino@gmail.com

          #5
          Re: Exeucte a system command in python script

          I am using python 2.4, so I don' t need to insteall that module
          separately.

          ken.carlino@gma il.com wrote:[color=blue]
          > Thanks I get this error 'NameError: global name 'call' is not defined"
          >
          > I already import 'subprocess'.
          >
          > Can you pleaes tell me what am I missing?
          >
          > Robert Kern wrote:[color=green]
          > > ken.carlino@gma il.com wrote:[color=darkred]
          > > > Hi,
          > > >
          > > > I would like to execute a shell command like this in python:
          > > > cmd = 'ant release -Dbuild=build_pr oxyonly -Drev=5.1.130f
          > > > -Dprops=\"-MIDP20_LARGE;PU SH_FEATURE=fals e;MIDlet-Version=5.0;ver sion=5.0;MIDlet-Icon=midicon15x 15.png;-FOUR_WAY_NAV_FE ATURE\"
          > > > -DThree_Branding =true'
          > > >
          > > > Which of the execl command described here should I use?
          > > > http://pydoc.org/1.6/os.html[/color]
          > >
          > > None. You should use the subprocess module in 2.4 (I really do hope that you're
          > > not using 1.6).
          > >
          > > http://docs.python.org/lib/module-subprocess.html
          > >
          > > It also works in Pythons as old as 2.2, but you'll have to install it
          > > separately. The website for the separate release is down at the moment, but when
          > > it comes back up:
          > >
          > > http://www.lysator.liu.se/~astrand/popen5/
          > >
          > > --
          > > Robert Kern
          > >
          > > "I have come to believe that the whole world is an enigma, a harmless enigma
          > > that is made terrible by our own mad attempt to interpret it as though it had
          > > an underlying truth."
          > > -- Umberto Eco[/color][/color]

          Comment

          • Steve Holden

            #6
            Re: Exeucte a system command in python script

            ken.carlino@gma il.com wrote:[color=blue]
            > I am using python 2.4, so I don' t need to insteall that module
            > separately.
            >
            > ken.carlino@gma il.com wrote:
            >[color=green]
            >>Thanks I get this error 'NameError: global name 'call' is not defined"
            >>
            >>I already import 'subprocess'.
            >>
            >>Can you pleaes tell me what am I missing?[/color][/color]

            Among other things you are missing the traceback that the Python
            interpreter provides with its error messages. This will point you to a
            particular line of the source. If you include a few lines of the source
            around that point, as well as a pasted copy of the traceback, we have
            some chance to determine the error without overtaxing our psychic powers.

            regards
            Steve
            --
            Steve Holden +44 150 684 7255 +1 800 494 3119
            Holden Web LLC/Ltd http://www.holdenweb.com
            Love me, love my blog http://holdenweb.blogspot.com
            Recent Ramblings http://del.icio.us/steve.holden

            Comment

            Working...