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.

3
  • 2
    Why don't you want to use the subprocess module? Commented Aug 28, 2013 at 22:28
  • Second that why not use subprocess? Commented Aug 28, 2013 at 22:31
  • Also, when you say it doesn't work, how do you know it's not working? Is there an error message? Commented Aug 28, 2013 at 22:39

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.