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. |
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] |
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 |
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) |
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! |
Glad you found a solution. Would you mind posting Popen line to see what format you found worked?
|
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}" |
All times are GMT -5. The time now is 10:55 PM. |