#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0

    Calling shell script from python


    Hi,

    I am trying to run shell script with xterm in python using subprocess.
    I not getting proper syntax for this.
    I have tried this piece of code but its not working.
    Code:
    #!/usr/bin/python 
    import subprocess 
    subprocess.call(["xterm -e","./script.sh", fname2])
    Here fname2 is argu to my script.

    Thanks!!!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0
    Got the solution

    subprocess.call(["xterm" ,"-e","./script.sh", fname2])
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    11
    Each string must be its own element. This includes switches. Also, xterm has a habit of self-destructing instantly, so you might want to add "hold" to your argument list:
    python Code:
    fname2 = 'a string you got somewhere else'
    exec_args = ['xterm', '-e', './some_script.sh', fname2, 'hold']
    subprocess.Popen(exec_args)

IMN logo majestic logo threadwatch logo seochat tools logo