Use whitespace in Windows command line parameters

1.5k Views Asked by At

My AutoIt script :

WinWaitActive("Open")
Send($CmdLine[1])
Send("{ENTER}")

I execute it from Java (passing a filepath to it):

String autoITExecutable = "C:\\filechooser.exe " + fileSource;

Name of file contains spaces, so it reads filename up to the first space and ignores the remainder. How do I correctly pass filepaths containing spaces as command line argument?

1

There are 1 best solutions below

2
On BEST ANSWER

Name of files contains spaces, but it reads filename only for the first space and cuts filename.

As per Documentation - Intro - Running Scripts:

If you're passing strings with spaces, then you will need to escape these using "double quotes" in your commandline string.

Without, text after space will be contained by next array element ($CmdLine[2] in this case). Java example:

String autoITExecutable = "C:\\filechooser.exe \"" + fileSource + "\"";

Unprocessed command line (single string) is available as per $CmdLineRaw from receiving AutoIt script.