0

I am writing a python script which uses os.system command to call a shell script.I need help understanding how I can pass the arguments to the shell script? Below is what I am trying..but it wouldn't work.

os.system('./script.sh arg1 arg2 arg3')

I do not want to use subprocess for calling the shell script. Any help is appreciated.

Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
user2727202
  • 11
  • 1
  • 1
  • 1

2 Answers2

1

Place your script and it's args into a string, see example below.

HTH

#!/usr/bin/env python

import os

arg3 = 'arg3'
cmd = '/bin/echo arg1 arg2 %s' % arg3

print 'running "%s"' % cmd

os.system(cmd)
gbp
  • 46
  • 2
0

If you insert the following line before os.system (...), you will likely see your problem.

print './script.sh arg1 arg2 arg3'

When developing this type of thing, it usually is useful to make sure the command really is what you expect, before you actually try it.

example:

def Cmd():
    return "something"

print Cmd()

when you are satisfied, comment out the print Cmd() line and use os.system (Cmd ()) or subprocess version.

Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
Fred Mitchell
  • 2,145
  • 2
  • 21
  • 29