how to execute shell script using python scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balnair
    New Member
    • Apr 2012
    • 1

    how to execute shell script using python scripts

    I have a shell file in location
    /home/transfer/check.sh

    I need to excecute this shell file using python script
  • Smygis
    New Member
    • Jun 2007
    • 126

    #2
    There is a module called subprocess. Look in to in.

    Comment

    • BadOPCode
      New Member
      • May 2012
      • 3

      #3
      Pfft... hate it when people post RTFM.
      If you just want a simple IO on the script file try

      Code:
      import commands
      
      output = commands.getstatusoutput('/home/transfer/check.sh')
      That will return back a tupple of the return code and the string output to console.
      If thats not quite right, you can check the commands module or if you need even more leverage with the console there is the module subprocess.

      Edit: That is assuming you banged your shell script. If not you will have to change that to '/bin/sh /home/transfer/check.sh' OR just bang the script and give it execute permission.
      Last edited by BadOPCode; May 30 '12, 10:14 PM. Reason: Incomplete info. Appended help on calling Bourne shells not banged.

      Comment

      • dwblas
        Recognized Expert Contributor
        • May 2008
        • 626

        #4
        We generally don't anwser questions that can be easily found with a Google http://www.google.com/search?client=...hannel=suggest because that indicates that the person is just lazy.

        Comment

        • dwblas
          Recognized Expert Contributor
          • May 2008
          • 626

          #5
          I like Doug Hellmann's explanation of subprocess.

          Comment

          Working...