1

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?

user4157124
  • 2,809
  • 13
  • 27
  • 42
plaidshirt
  • 5,189
  • 19
  • 91
  • 181

1 Answers1

3

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.

user4157124
  • 2,809
  • 13
  • 27
  • 42
  • 1
    The assumption here is that filechooser.exe parses double quotes in its command line similarly to `CommandLineToArgvW` and VC++ `argv` parsing. It's a good assumption, but remember that Windows applications can really do whatever they want here. `CreateProcess` may parse the command line up to `"C:\\filechooser.exe "` if `lpApplicationName` is omitted, but the application itself just gets the unparsed string. – Eryk Sun Jun 01 '18 at 23:59
  • @eryksun Added statement on availability of unparsed command line string. – user4157124 Jun 06 '18 at 00:06