LinuxQuestions.org
Review your favorite Linux distribution.
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 01-14-2011, 10:48 AM   #1
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Rep: Reputation: 21
python passing multiple args to bash


I have a text string I want to pass as the second arg to a bash shell.
fill = str(" -filltype FT3,"+spacing+",180' ") # must included the trailing single quote and spaces

my python line is :

subprocess.Popen("$HOME/bin/mirror-above.sh "+gap, fill, stdout=PIPE, shell=True).communicate()[0]

the first arg "gap" works great and the bash shell uses it as $1
I need "fill" passed along as $2 intact

here is the bash line:

FILL = $2
pstoedit -flat .01 -yshift $YSHIFT -usebbfrominput -f 'hpgl: -pencolorsfromfile -penplotter $FILL in >> out

as you can see after the -f it has to be in single quotes and $FILL will complete the single quote

Nothing is getting passed as a second arg from python, I did have the first word at one time but that was 85 tries ago and forgot how I did it!

The bash script complains about an unterminated quote.
 
Old 01-14-2011, 11:30 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Well assuming they are both strings, is it not a simple case of replacing the comma with a concatenated space?
Code:
subprocess.Popen("$HOME/bin/mirror-above.sh "+gap + " " + fill, stdout=PIPE, shell=True).communicate()[0]
 
Old 01-14-2011, 12:06 PM   #3
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
error

/bin/sh: Syntax error: Unterminated quoted string
I've been getting this error for hours!
FILL=$2
echo $2
echo $FILL
In the shell prints nothing...
I also tried removing the trailing ' from python fill variable and add it to the command string
subprocess.Popen("$HOME/bin/mirror-above.sh "+gap + " " + fill + "'", stdout=PIPE, shell=True).communicate()[0]

still same error....
still seems like it's not getting passed
it's for sure assigned to fill as
print fill gets -filltype FT3,10,90
 
Old 01-14-2011, 03:21 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
I think it would be better not to let the shell perform argument splitting, it's too hard to get the multiple levels of quoting right.

Code:
subprocess.Popen([os.getenv("HOME")+"/bin/mirror-above.sh", gap, fill], shell=False, stdout=subprocess.PIPE)

Last edited by ntubski; 01-14-2011 at 03:22 PM. Reason: grammar
 
Old 01-15-2011, 07:31 AM   #5
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
done!

I finally got it had to add some quotes around the fill arg and edit the shell script a lot but hey it works great now.

Thanks for all your help!
 
Old 01-15-2011, 09:52 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Glad you found a solution. Would you mind posting Popen line to see what format you found worked?
 
Old 01-16-2011, 05:14 AM   #7
gary_in_springhill
Member
 
Registered: Mar 2008
Posts: 136

Original Poster
Rep: Reputation: 21
solution

python =

subprocess.Popen([os.getenv("HOME")+"/bin/mirror-above.sh", gap, 'fill'], shell=False, stdout=subprocess.PIPE)

bash =

FILL=" -filltype FT3,$2"
pstoedit -v -flat .01 -yshift $YSHIFT -xscale $SCALE -yscale $SCALE -usebbfrominput -f "hpgl:-pencolorsfromfile -penplotter ${FILL}"
 
  


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
Passing args in terminal window is OK. but isn't when passing in GNOME launcher why? majrys1962 Debian 0 11-18-2008 06:00 PM
ARGS in bash script investmentbnker75 Programming 1 10-21-2008 01:03 AM
Passing args to port / make and apache rob0t *BSD 4 08-27-2008 10:34 AM
Passing args in an IOCTL neerajb Linux - Software 0 04-20-2006 05:51 AM
perl: passing 2 individual arrays/lists as args johnMG Programming 12 04-18-2005 03:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:24 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration