LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-04-2010, 08:42 AM   #1
mfb
LQ Newbie
 
Registered: Aug 2007
Posts: 20

Rep: Reputation: 0
calling bash script with more than one variable from python script


I am calling a bash shell script from a python script trying to pass several arguments to the bash script with no succes can this be done? I have researched (google) with no clear indication of how to achieve this. Using "os.system"
 
Old 10-04-2010, 09:43 AM   #2
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 227Reputation: 227Reputation: 227
Works for for me. I have the follwoing bash script called args.sh:
Code:
#!/bin/bash
echo "Passed Arg 1:"$1
echo "Passed Arg 2:"$2
echo "Passed Arg 3:"$3
being ran by the following python code I've called args.py:
Code:
#!/bin/env python
import os
os.system("./args.sh a1 a2 a3")
you can see a1 a2 and a3 are passed to args.sh and output when args.py is ran.
 
Old 10-06-2010, 06:48 AM   #3
mfb
LQ Newbie
 
Registered: Aug 2007
Posts: 20

Original Poster
Rep: Reputation: 0
more data

I dont think that I described the complete issue.

Not only do I want to pass the arguments but these are python variables captured with the getvalue() from a Pmw EntryField. Not sure how to refrence the value in Python.

Bash

value = "red"
echo $value

what is the python equivelent if any

Python

value = self.getvalue()

when i pass the "value" variable to bash script and echo get "value" when the actual value of variable is "red"

in python when I print the value it shows "red"

hope i have explained the issue well thanks for any light that can be shed new to Python
 
Old 10-06-2010, 08:44 AM   #4
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 227Reputation: 227Reputation: 227
Quote:
Not only do I want to pass the arguments but these are python variables captured with the getvalue() from a Pmw EntryField. Not sure how to refrence the value in Python.
I think I follow you here. This is a simple change to my original args.py where value1,value2 and value3 are possibly set by a call to YourClassInstance.getvalue() - here I've just simply set red,green and blue as examples but it's easy to make the substitutions. Python's string formatting is what you want and here is a simple example.
Quote:
#!/bin/env python
import os
value1="red"
value2="blue"
value3="green"
os.system("./args.sh %s %s %s" % (value1,value2,value3))
The string formatting substitutes value1, value2 and value3 for the string format "%s" specifiers in the string before the "%" operator.
 
Old 10-12-2010, 06:51 AM   #5
mfb
LQ Newbie
 
Registered: Aug 2007
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks for the help...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a bash shell script from within another script dedman Linux - Software 7 04-24-2010 08:53 PM
bash script: use the directory of the script file as variable? phling Linux - Newbie 12 01-16-2010 07:16 PM
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 08:01 AM
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM
how to pass a variable from a called script back to the calling script steven.c.banks Linux - General 2 05-05-2008 02:00 PM


All times are GMT -5. The time now is 05:21 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration