use Run with a variable containing space Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
xypha
Posts: 24
Joined: 24 Apr 2020, 04:14

use Run with a variable containing space

10 Dec 2023, 09:45

In AutoHotKey v1, the following code worked

Code: Select all

MediaNameNoExt := "example1 example2"
Run "D:\Everything.exe" -maximized -search "%MediaNameNoExt%"
In AutoHotKey v2, when I run below code, only "example1" is passed to Everything.exe, but not "example2" - it causes an error or it is not passed at all because of the space preceding it.

Code: Select all

A_Clipboard := "example1 example2"
Run '"D:\Everything.exe" -maximized -search ' . A_Clipboard
I have tried adding () but that didn't work.
I have tried adding "" and %% but that didn't work.
I tried changing the positions of the double and single quotes but none of those attempts worked.
I have tried changing MediaNameNoExt to A_Clipboard but that didn't work either.

How can I get this to work?
vmech
Posts: 376
Joined: 25 Aug 2019, 13:03

Re: use Run with a variable containing space

10 Dec 2023, 10:51

null
Last edited by vmech on 15 Dec 2023, 04:09, edited 1 time in total.
Please post your script code inside [code] ... [/code] block. Thank you.
neogna2
Posts: 600
Joined: 15 Sep 2016, 15:44

Re: use Run with a variable containing space  Topic is solved

10 Dec 2023, 11:13

Code: Select all

Run '"D:\Everything.exe" -maximized -search "' A_Clipboard '"'
Read https://www.autohotkey.com/docs/v2/Language.htm#strings for how to enclose literal strings with " and '
User avatar
xypha
Posts: 24
Joined: 24 Apr 2020, 04:14

Re: use Run with a variable containing space

15 Dec 2023, 03:00

Thanks @neogna2
It worked.
I did read the docs, but there was no clear mention of putting variables into single AND double quotes. It makes sense now though.

Thanks @vmech for replying
Your response raised an error `Error: Unexpected operator following literal string.`
User avatar
boiler
Posts: 17390
Joined: 21 Dec 2014, 02:44

Re: use Run with a variable containing space

15 Dec 2023, 03:25

That’s because no one put quotes around a variable. They used both in segments of a literal string so the string would contain the opposite type of quote. See Strings / Text.

Looks like vmech accidentally left part of the literal string unquoted.
vmech
Posts: 376
Joined: 25 Aug 2019, 13:03

Re: use Run with a variable containing space

15 Dec 2023, 04:14

I don't use this syntax, so that's probably why I made a mistake. In the future, I think I should ignore such topics.
Please post your script code inside [code] ... [/code] block. Thank you.
User avatar
xypha
Posts: 24
Joined: 24 Apr 2020, 04:14

Re: use Run with a variable containing space

15 Dec 2023, 05:37

vmech wrote:
15 Dec 2023, 04:14
I don't use this syntax, so that's probably why I made a mistake. In the future, I think I should ignore such topics.
Don't do that... Seeing the difference between your answer and neogna2's answer helped me make sense of the syntax. It was helpful.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 49 guests