Command line arguments not captured by `OS.get_cmdline_args()`

Godot Version



I’m trying to get some config file path as command line argument to my project executable, but printing OS.get_cmdline_args() returns an empty array. So does OS.get_cmdline_user_args().

My codes looks something like this:


func _ready():
    print("Cmd line args: %s" % [OS.get_cmdline_args()])

I’ve tried with

$ myproject --file=path/to/my/file
$ myproject --file path/to/my/file

Any pointers on what I’m not getting right?

Try myproject -- file path/to/my/file

It doesn’t work either

You need to use get_cmdline_user_args if you want custom args, please see the documentation

1 Like

I have tried both, get_cmdline_args() and get_cmdline_user_args(). They both return emtpy arrays in all the options described above.

I cannot replicate that, I just tried and it works for me, try myproject -- --file path/to/my/file

Otherwise try 4.2.2 to make sure this isn’t a bug that has been solved

I found where the problem was. I’m on NixOS. In order to run the binary I need to do it with

$ steam-run myapp

I had created a shell script as a shortcut and was not passing the arguments of the script as arguments to steam-run myapp. If I do that, the get_cmdline_*args() work as expected.

Thanks @athousandships for your kind help.

1 Like