I have a little CSH script that calls a python script. I am trying to pass a string to a python script by calling a CSH script, but it breaks the whitespace by processing with argparse in python. I need this CSH script because after executing python there is some old code that I need to use.
CSH script:
Just a python script call passing all python string argumentssys.argv
#!/bin/csh
echo $argv[1-]
python soocc.py $argv[1-]
python script:
This script must identify an argument of type: -opt "+arg1=1 +arg2=3 +arg3=0"before parsing argparse. So, first it identifies if there is -optin sys.argv, write a line in the variable, and then delete -opt "arg1=1 arg2=3 arg3=0"from sys.argv. This way argparse will not process -opt(because argparse looks at + arg1 as an argument, even if it is inside a double quote).
print sys.argv
if '-opt' in sys.argv:
xipdef.opt = sys.argv[sys.argv.index('-opt') + 1]
sys.argv.remove(sys.argv[sys.argv.index('-opt') + 1])
sys.argv.remove(sys.argv[sys.argv.index('-opt')])
print sys.argv
Problems:
soocc.csh -opt '"+arg1=1 +arg2=3 +arg3=0"'
Returns csh echo:
-opt "+arg1=1 +arg2=3 +arg3=0"
So far so good. The problem is when the arguments are passed to a python script. First result print sys.argv:
['soocc.csh','-opt', '"+arg1=1', '+arg2=3', '+arg3=0"']
The string inside the double quotes is split into a space on sys.argv. I was expecting something like:
['soocc.csh','-opt', "+arg1=1 +arg2=3 +arg3=0"]
Can anyone help me find what is wrong?