You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Command line args set in ProjectSettings editor/main_run_args are split at spaces, even if they are quoted.
This only occurs if started from the editor and only on Mac and Linux.
The only difference in 4 is that the main scene is also a command line arg (res://Main.tscn) for some reason.. That might be another bug
Here is a workaround to splice the args back together.
# Reverses a bug in Godot, which splits input strings at spaces even if they are quoted# e.g. --arg="some value" becomes [ --arg="some, value" ]# this only occurs with args in that format. --arg "some value" is safestaticfuncfix_godot_cmdline_args_string_space_splitting(args: PoolStringArray) ->PoolStringArray:
ifnotOS.has_feature("editor"): # only happens in editor buildsreturnargsifOS.has_feature("Windows"): # windows is unaffectedreturnargsvarfixed_args:=PoolStringArray([])
varfixed_arg:=""# if we encounter an argument that contains [code]=[/code] followed by a quote,# or an argument that starts with a quote, take all following args and# concatenate them into one, until we find the closing quoteforarginargs:
vararg_string:=argasStringif'="'inarg_stringor'="'infixed_argor \
arg_string.begins_with('"') orfixed_arg.begins_with('"'):
ifnotfixed_arg=="":
fixed_arg+=" "fixed_arg+=arg_stringifarg_string.ends_with('"'):
fixed_args.append(fixed_arg.trim_prefix(" "))
fixed_arg=""continue# same thing for single quoteselif"='"inarg_stringor"='"infixed_arg \
orarg_string.begins_with("'") orfixed_arg.begins_with("'"):
ifnotfixed_arg=="":
fixed_arg+=" "fixed_arg+=arg_stringifarg_string.ends_with("'"):
fixed_args.append(fixed_arg.trim_prefix(" "))
fixed_arg=""continueelse:
fixed_args.append(arg_string)
returnfixed_args
Steps to reproduce
Set some args with spaces in ProjectSettings editor/main_run_args.
E.g. --arg="string with spaces" --second-arg 'with spaces'
[--arg="string, with, spaces", --second-arg, 'with, spaces']
single arg: --arg="string
single arg: with
single arg: spaces"
single arg: --second-arg
single arg: 'with
single arg: spaces'
---
[--arg="string with spaces", --second-arg, 'with spaces']
fixed arg: --arg="string with spaces"
fixed arg: --second-arg
fixed arg: 'with spaces'
This is because Main Run Args is only applied when running the project from the editor.
We could have a separate project setting for command line arguments to pass even to an exported project (or if running the project directly from the command line in general), but that's proposal territory.
If you happen to follow my proposal in the referencing issue above to convert that args setting to a string array, maybe it makes sense here too (and any other similar args settings everywhere). It's what e.g. VSCode's tasks.json does - it's simpler=safer to handle without mistakes, and clearer to the user too.
Godot version
3.5.stable, 4 rc1
System information
MacOS 12.6.1, Linux not sure which
Issue description
Command line args set in ProjectSettings
editor/main_run_args
are split at spaces, even if they are quoted.This only occurs if started from the editor and only on Mac and Linux.
The only difference in 4 is that the main scene is also a command line arg (
res://Main.tscn
) for some reason.. That might be another bugHere is a workaround to splice the args back together.
Steps to reproduce
Set some args with spaces in ProjectSettings
editor/main_run_args
.E.g.
--arg="string with spaces" --second-arg 'with spaces'
print them out
result
Minimal reproduction project
Works in 3.5 and 4rc1 (the run args just have to be set again after conversion)
CmdLineArgSplitReproduction.zip
The text was updated successfully, but these errors were encountered: