-1

i'm writing a python script to execute shell command, and i'm taking arguments and i want to pass the value of that to the command

#!/usr/bin/env python

import commands
import subprocess
import sys

command = commands.getoutput('fs_cli -x "sofia profile external restart"')

this code works fine

when i try to take the argument and pass to command it fails

command = commands.getoutput('fs_cli -x "sofia profile" + sys.argv[1] + " restart"')

supp folks

frodo
  • 51
  • 2
  • 11

3 Answers3

1

You should write:

command = commands.getoutput('fs_cli -x "sofia profile ' + sys.argv[1] + ' restart"')
Akalyn
  • 145
  • 6
0

Take a look to argparse and subprocess.

0

One of the way to do this is to convert your command that you want to execute into string and then execute it as eval()

example : eval(expression/command in string)