hexagon logo

String settings to run process

cmd string is formed using below commands. Process is not executed properly due to spaces in the path. Please suggest.
​exe_path = "C:\Program Files (x86)\test\1.0\CAPA1.exe"
filename = "C:\Disck D\Patran/test4.bdf"
cmd = exe_path//" -p "//filename//" "//Part_list.txt
$# STRING cmd[512] = "C:\Program Files (x86)\test\1.0\CAPA1.exe -p C:\Disck D\Patran/test4.bdf Part_list.txt"
status = utl_process_spawn(cmd, TRUE)
  • Bala, when you have spaces in filenames, you need to protect them with quotes when you run them on the command line. So, to run your process from the command line, you would type something like this:
    "C:\Program Files (x86)\test\1.0\CAPA1.exe" -p C:\DisckD\Patran\test4.bdf Part_list.txt
     
    You need to do the same with your PCL strings. That takes extra care when you create your strings, as you need extra quotes. Use two double quotes inside a string for each quote you want.
    Use this declaration of exe_path to add double quotes:
    ​exe_path = " ""C:\Program Files (x86)\test\1.0\CAPA1.exe"" "
     
    That should solve your problem.
    As a side note, I would use extra double quotes for any filenames if they "could" have spaces in the name.
     
    Here are 2 examples showing the difference submiting Python scripts from Patran.
    The second script has spaces in the file name.
    STRING pcmd[10]="python"
    STRING script1[40]="print_column_names.py"
    STRING my_cmd[80]
    my_cmd=pcmd // " " // script1
    INTEGER status
    status = utl_process_spawn(my_cmd, TRUE)
    STRING script2[80]=" ""print column names.py"" "
    my_cmd=pcmd // " " // script2
    status = utl_process_spawn(my_cmd, TRUE)
     
    You will get an error if script2 is defined without the extra quotes.
     
    Also, check string lengths when concatenating to avoid unexpected truncation with 2 long strings. (Not that I've ever made that mistake.)