execute a shell script from a python script

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

    execute a shell script from a python script

    Hi all, I know nothing about Python. What I need to do is to get a
    Python script to execute a local shell script. I do not need any
    output. What would be th eeasiest way to accomplish this?

    Thanks!

  • Thomas Nelson

    #2
    Re: execute a shell script from a python script

    If your script is foo.sh and takes args:
    import subprocess
    subprocess.call (["foo.sh","a rgs"],shell=True)
    Should work fine. check out


    Enjoy,
    THN

    spec wrote:
    Hi all, I know nothing about Python. What I need to do is to get a
    Python script to execute a local shell script. I do not need any
    output. What would be th eeasiest way to accomplish this?
    >
    Thanks!

    Comment

    • spec

      #3
      Re: execute a shell script from a python script

      Thanks, actually there are no args, is there something even simpler?

      Thanks
      Frank


      Thomas Nelson wrote:
      If your script is foo.sh and takes args:
      import subprocess
      subprocess.call (["foo.sh","a rgs"],shell=True)
      Should work fine. check out

      >
      Enjoy,
      THN
      >
      spec wrote:
      Hi all, I know nothing about Python. What I need to do is to get a
      Python script to execute a local shell script. I do not need any
      output. What would be th eeasiest way to accomplish this?

      Thanks!

      Comment

      • John McMonagle

        #4
        Re: execute a shell script from a python script

        On Mon, 2006-07-17 at 16:59 -0700, spec wrote:
        Thanks, actually there are no args, is there something even simpler?
        >
        Thanks
        Frank
        >
        >
        Thomas Nelson wrote:
        If your script is foo.sh and takes args:
        import subprocess
        subprocess.call (["foo.sh","a rgs"],shell=True)
        Should work fine. check out


        Enjoy,
        THN

        spec wrote:
        Hi all, I know nothing about Python. What I need to do is to get a
        Python script to execute a local shell script. I do not need any
        output. What would be th eeasiest way to accomplish this?
        >
        Thanks!
        >
        --

        >
        Check out os.popen4 or the commands module.




        --
        This message has been scanned for viruses and
        dangerous content by MailScanner, and is
        believed to be clean.

        Comment

        • Simon Forman

          #5
          Re: execute a shell script from a python script

          spec wrote:
          Thanks, actually there are no args, is there something even simpler?
          >
          Thanks
          Frank
          you could try os.system()
          >From the docs:
          system(command)
          Execute the command (a string) in a subshell. This is implemented
          by calling the Standard C function system(), and has the same
          limitations. Changes to posix.environ, sys.stdin, etc. are not
          reflected in the environment of the executed command.

          On Unix, the return value is the exit status of the process encoded
          in the format specified for wait(). Note that POSIX does not specify
          the meaning of the return value of the C system() function, so the
          return value of the Python function is system-dependent.

          On Windows, the return value is that returned by the system shell
          after running command, given by the Windows environment variable
          COMSPEC: on command.com systems (Windows 95, 98 and ME) this is always
          0; on cmd.exe systems (Windows NT, 2000 and XP) this is the exit status
          of the command run; on systems using a non-native shell, consult your
          shell documentation.

          Availability: Macintosh, Unix, Windows.

          Comment

          • Cameron Laird

            #6
            Re: execute a shell script from a python script

            In article <1153187926.407 414.201530@m73g 2000cwd.googleg roups.com>,
            Simon Forman <rogue_pedro@ya hoo.comwrote:
            >spec wrote:
            >Thanks, actually there are no args, is there something even simpler?
            >>
            >Thanks
            >Frank
            >
            >you could try os.system()
            >
            >>From the docs:
            >
            >system(command )

            Comment

            • Thomas Nelson

              #7
              Re: execute a shell script from a python script

              As described in the docs I pointed to before:
              subprocess.call ("foo.sh",shell =True)
              Is the way to do it without args. I think it is simplest to learn the
              subprocess module because (quoting from the docs) this module intends
              to replace several other, older modules and functions, such as:
              os.system
              os.spawn*
              os.popen*
              popen2.*
              commands.*
              This way you only need to learn one thing. Actually I would like to
              see some of these older functions deprecated.

              THN

              Cameron Laird wrote:
              In article <1153187926.407 414.201530@m73g 2000cwd.googleg roups.com>,
              Simon Forman <rogue_pedro@ya hoo.comwrote:
              spec wrote:
              Thanks, actually there are no args, is there something even simpler?
              >
              Thanks
              Frank
              you could try os.system()
              >From the docs:
              system(command)
              .
              [more detail]
              .
              .
              I'm concerned the follow-ups in this thread have been too subtle.
              Here is what you need to know: use system(). A model such as
              >
              import os
              os.system("my_s cript")
              >
              fulfills exactly the requirements the original poster described.

              Comment

              • Cameron Laird

                #8
                Re: execute a shell script from a python script

                In article <1153243296.095 949.268520@s13g 2000cwa.googleg roups.com>,
                Thomas Nelson <thn@mail.utexa s.eduwrote:
                >As described in the docs I pointed to before:
                >subprocess.cal l("foo.sh",shel l=True)
                >Is the way to do it without args. I think it is simplest to learn the
                >subprocess module because (quoting from the docs) this module intends
                >to replace several other, older modules and functions, such as:
                >os.system
                >os.spawn*
                >os.popen*
                >popen2.*
                >commands.*
                >This way you only need to learn one thing. Actually I would like to
                >see some of these older functions deprecated.

                Comment

                Working...