FileSelect'd filename doesn't work as a param for RunWait

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
DaveT1
Posts: 224
Joined: 07 Oct 2014, 11:23

FileSelect'd filename doesn't work as a param for RunWait

Post by DaveT1 » 17 Jan 2022, 14:40

I'm sure this must be easy, it's just I can't figure it out - any pointers gratefully received:

So, this works as expected:
Runwait "Notepad.exe" ' "D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt" '

and this also works as expected:
name := ' "D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt" '
Runwait "Notepad.exe" Name


But this DOESN'T work (see code comments for more detail):
Name := FileSelect(,,, "*.txt") ;Selected file = "D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt"
Name := " `' `"" . Name . "`" `'"
MsgBox(Name) ;name = ' "D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt" '
Runwait "Notepad.exe" Name ;Popup err = "The filename, directory name, or volume label syntax is incorrect." Notepad starts but is empty.


I'd be really grateful for your thoughts.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: FileSelect'd filename doesn't work as a param for RunWait

Post by swagfag » 17 Jan 2022, 16:51

i dont understand what ure trying to do adding these quotes all over the place. u probably dont either
top case

Code: Select all

u write:        "Notepad.exe" ' "D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt" '
RunWait sees:    Notepad.exe⎵"D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt"⎵
works
middle case, same as top case

Code: Select all

u write:        "Notepad.exe" ' "D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt" '
RunWait sees:    Notepad.exe⎵"D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt"⎵
works
bottom case

Code: Select all

u write:        "Notepad.exe" " `' `""D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt"`" `'"
RunWait sees:    Notepad.exe⎵'⎵"D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt"⎵'
womp, womp. get rid of these single-quote+spaces
Name := " `' `"" . Name . "`" `'" should have been Name := " `"" . Name . "`"" or Name := ' "' . Name . '"'

DaveT1
Posts: 224
Joined: 07 Oct 2014, 11:23

Re: FileSelect'd filename doesn't work as a param for RunWait

Post by DaveT1 » 18 Jan 2022, 05:07

Thanks for the reply.

Yous seem to suggest that

Runwait "Notepad.exe" "D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt"

works. Did you try? If I run this, Notepad does not start and microsoft pops up the "you need a new app to open this notepad.exed link" (and yes, is does write it as "notepad.exed" - not sure what that means). So this didn't work.

So, this definitely works for me as expected (ie., the target file is opened in Notepad):

Runwait "Notepad.exe" ' "D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt" '

V2 help for Run says "If a parameter contains spaces, it is safest to enclose it in double quotes (even though it may work without them in some cases)." As it didn't work when not surrounded by double quotes I addedd them. But, as explained above, this still doesn't work. Later in the same help section under Remarks it says if running via cmd.exe to enclose any part of the string that has spaces in single quote marks with spaces, as shown in my top case. I have spaces, and tried this without expectation, but it worked! I could find no other combination that makes this work. So, I assumed that this combination of single-quotes, double-quotes and spaces in the parameter string was what I needed in cases 2 and 3.

Update: Inspired by your suggestions, I've just found that this combo also works:
Runwait "Notepad.exe" ' D:\AutoHotKey\My AHK projects\RunXRef+\XRef+ExcludedWordsList.txt '
middle case, same as top case
No, not quite. It introduces the Run parameter as a var, as a step towards the 3rd case (which is what I'm trying to achieve). The net effect should be the same, and indeed it is!
should have been Name := " `"" . Name . "`""
This doesn't work for me. Instead throws an AUTOHOTKEY error - "Failed attempt to launch and program or document:"
should have been Name := ' "' . Name . '"'
Ah, now this works - :bravo: Though I must confess I don't know why - I thought we needed double quotes for text and to escape literal chars within those double quotes! I need to read around some more perhaps.

And following on from the Update above, it turns out this also works:
Name := " `'" . Name . "`'"

Very many thanks for unlocking what I needed to do here - have been going round and round with this one.

Post Reply

Return to “Ask for Help (v2)”