I am trying to pass several parameters from a python script to a bash script in the following way:
input_string = pathToScript + " " + input1 + " " + input2 + " " + input3 + " " + input4 + " " + \
input5 + " " + input6 + " " + input7 + " " + input8 + " " + input9 + " " + input10
args = shlex.split(input_string)
p = subprocess.Popen(args)
where all the inputX are strings. Each of these arguments shall be passed to the script, whose path is stored in the variable pathToScript. I now want to be able to catch these parameters in the bash script like I usually do:
#No input check yet...
history_file = "$1"
folder_history_file = "$2"
folder_bml_files = "$3"
separate_temperature = "$4"
separate_temperature_col_index = "$5"
separate_sight = "$6"
separate_sight_col_index = "$7"
separate_CO = "$8"
separate_CO_col_index = "$9"
separate_radiation = "$10"
This causes errors like line 61: separate_CO_col_index: command not found for all these lines and the errors do not appear in the same way the lines are ordered. In other words such error on line 61 is sometimes caught before the one on line 60, it seems from the output in Eclipse (I use PyDev in Eclipse).
Is it not possible to run the bash script like this? I have tried following the method in ch. 17.1.1.1 here, but I may not have understood it correctly: python docs
The errors in bash appear because you put spaces around the
=. You should useinstead of
When you put spaces there, Bash thinks the line is a command invocation and tries to run
history_fileas a command.In your Python script, you can simply use:
instead of what you have. This is simpler, and will work correctly if the arguments contain spaces, which your current code will fail on. There’s no point in building the
input_stringstring only to split it back in the following line.