Gpt command line: xml file doesn't read variable containing space


I’m building all my process thx to SNAP_CommandLine_Tutorial.pdf and senbox.atlassian.snap.

here an .xml example :

< demName > ${SRTM}< /demName >

Then I use this format in my script:


SRTM=“GETASSE30” runs well.
SRTM=“SRTM 1sec HGT” breaks coz gpt does not recognize multiple strings (or space character I don’t know…)

When I look into the Snap’s generated xml, it’s written:

< demName >SRTM 1Sec HGT< /demName >

So what should I write to use the “SRTM 1Sec HGT” in my scripts ?

many thanks!

Here the solution:

def to_cmd_string(unquoted_str: str) -> str:
    Add quotes around the string in order to make the command understand it's a string
    (useful with tricky symbols like & or white spaces):

    # This str wont work in the terminal without quotes (because of the &)
    pb_str = r"D:\Minab_4-DA&VHR\Minab_4-DA&VHR.shp"
    # >> "\"D:\Minab_4-DA&VHR\Minab_4-DA&VHR.shp\""

        unquoted_str (str): String to update

        str: Quoted string
    cmd_str = unquoted_str
    if not unquoted_str.startswith('"'):
        cmd_str = '"' + cmd_str
    if not unquoted_str.endswith('"'):
        cmd_str = cmd_str + '"'
    return cmd_str

A double double quote was needed: str = " \ "string \ " "

1 Like

This works for me…

import subprocess

command = [str(path_to_gpt), str(path_to_xml), f'-Pargument="{some_variable}"']