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

Hi

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:

‘-PSRTM={}’.format(SRTM)

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!
Ari

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):

    ```python
    # 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"
    to_cmd_string(pb_str)
    # >> "\"D:\Minab_4-DA&VHR\Minab_4-DA&VHR.shp\""
    ```

    Args:
        unquoted_str (str): String to update

    Returns:
        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}"']
subprocess.call(command)