I have two simple scripts - I am trying to pass some information (date as input into the python script) to the bash script. Here's the python one:
#!/usr/local/bin/python
import os
import sys
import subprocess
year = "2012"
month = "5"
month_name = "may"
file = open('date.tmp','w')
file.write(year + "\n")
file.write(month + "\n")
file.write(month_name + "\n")
file.close
subprocess.call("/home/lukasz/bashdate.sh")
And here's the bash one:
#!/bin/bash
cat /home/lukasz/date.tmp | \
while read CMD; do
echo -e $CMD
done
rm /home/lukasz/date.tmp
Python script works fine without issues. It calls the bash script but it looks like the while loop just does not run. I know the bash script does run overall because the rm command gets executed and the date.tmp file is removed. However if I comment out the subprocess call in python then run the bash script manually it works fine displaying each line.
Brief explanation of what I am trying to accomplish. I have a python script that exports a very large DB to CSV (almost 300 tables and a few gigs of data) which then calls the bash script to zip the CSVs into one file and move it to another location. I need to pass the month and year supplied to the python script to the bash script.
subprocess.call(["/home/lukasz/bashdate.sh", year, month, month_name])
in Python, and thenyear=$1; month=$2; month_name=$3
in Bash. To check the number of arguments passed to the Bash script, useif [ $# -lt 3 ]; then echo "More arguments please."; exit 1; fi
(or change-lt
to-eq
if you want exactly three arguments). – Blair Jan 2 '13 at 21:46shutil
and/orzipfile
andos
in the standard library? – abarnert Jan 2 '13 at 22:53bash
script, it's impossible to know whether it's possible to do the same thing in Python. But I don't understand why you think Python can't read files in/tmp
. I'm also not sure why you think a solution you can't figure out yourself is "far simpler" than something you probably could figure out with no problems. – abarnert Jan 3 '13 at 19:43