Command prompt opened by AutoHotkey doesn't detect SCSS/SASS system PATH variables, but regular CMD does

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sjdheunaskdf9384348
Posts: 14
Joined: 29 Dec 2015, 16:52

Command prompt opened by AutoHotkey doesn't detect SCSS/SASS system PATH variables, but regular CMD does

09 Mar 2018, 13:20

SOLVED: Restarting my script (NOT Reload) ended up fixing the problem, as it allowed AutoHotkey to retrieve the updated PATH. Restarting my system would have also fixed it, the classic "turn it off and back on again" stays strong as always.

I am having a weird problem with AutoHotkey that I've never had before. I'm using AutoHotkey v2, and am trying to use a simple hotkey to launch the SCSS "watch" function while working on a website. I installed the SCSS/SASS gem using Ruby on Windows 10, and it is supposed to install to the PATH. It appears to have done that, because if I manually open a CMD or CMDer window and type "SCSS -v" it outputs the version just fine. Same goes with running commands using SCSS.

However, launching command prompt using AutoHotkey isn't detecting that SCSS path at all.

Code: Select all

Run A_ComSpec ' /k "scss --watch C:\Users\User\Desktop\coding\website\public\scss/:C:\Users\User\Desktop\coding\website\public\css/" '
When that is run using AutoHotkey, it outputs "'scss' is not recognized as an internal or external command, operable program or batch file." Even if I change that code to launch directly from the SCSS path, it has the same result. When I manually open CMD and type "scss --watch C:\Users\User\Desktop\coding\website\public\scss/:C:\Users\User\Desktop\coding\website\public\css/" it runs just fine.

Is there some difference between the CMD that AutoHotkey runs via A_ComSpec? I even tried having it first change directories to "C:\Windows\System32" which is what the normal CMD defaults to when it first opens, but it didn't make a difference.

Hopefully I explained this okay, feel free to ask for clarification if needed, and I'll do my best to answer. I've never had this problem before, I even tried reinstalling Ruby and SCSS but it didn't make a difference.

--Edit--
I should mention that AutoHotkey works fine with other environment variables, such as "light-server" which was installed via NPM. It seems to be some weird problem with Ruby and gems or something, but I could be wrong.

--Edit #2--
It seems to be a problem with command prompt being launched from any other program, and not from Explorer directly. I launched CMD from Everything (https://www.voidtools.com/) and it also wasn't able to detect SCSS. But if I launch CMD directly from Explorer (either navigating to C:\Windows\System32 or by searching in the start menu) it works just fine. If anyone knows a workaround for that, please let me know! However, this doesn't seem to be a problem with AutoHotkey specifically.

--Edit #3, basically solved--
So I ended up "fixing" this by having AutoHotkey set the temporary environment variable, then running the same code as before. Here is the final code:

Code: Select all

#If WinActive("ahk_exe sublime_text.exe")

XButton2::
EnvSet("PATH","C:\_ruby\bin")
Run A_ComSpec ' /k "scss --watch C:\Users\User\Desktop\coding\website\public\scss/:C:\Users\User\Desktop\coding\website\public\css/"'
Return
Still not sure why there is such a problem with environment variables being detected by CMD launched from other programs, but this works well enough for my needs. I'll leave this up in case someone has this problem in the future.
Last edited by sjdheunaskdf9384348 on 16 Mar 2018, 15:05, edited 4 times in total.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Command prompt opened by AutoHotkey doesn't detect SCSS/SASS system PATH variables, but regular CMD does

10 Mar 2018, 23:02

Each newly launched process inherits a copy of the environment (the block of environment variables) of the process which launched it, unless the environment was specified when launching the process. However, if you launch a 32-bit process from a 64-bit process or vice versa, there will be some differences. Before reading your edits, I would assume that the cause of your problem is one of these two:
  • The process which launches AutoHotkey does not have the expected PATH value.
  • AutoHotkey is 32-bit and the CMD you are testing with is 64-bit, or vice versa.
It seems to be a problem with command prompt being launched from any other program, and not from Explorer directly.
This will almost certainly be the case if you have not rebooted since the PATH variable was changed (for the system or current user in Control Panel, or via the registry, such as by an installer), since most programs do not update their environment variables automatically. Even programs which do this might not at all if the process which changed the variables did not send the appropriate system-wide signal. If you reboot, all processes are restarted and should pick up whatever values have been set for environment variables in the registry.
sjdheunaskdf9384348
Posts: 14
Joined: 29 Dec 2015, 16:52

Re: Command prompt opened by AutoHotkey doesn't detect SCSS/SASS system PATH variables, but regular CMD does

16 Mar 2018, 15:01

Hey lexikos, thanks for taking the time to respond!

I forgot I had made this post, but I ended up fixing this 100% by fully exiting my script and starting again. I can run my initial command without having to mess with EnvSet or anything like that.

But you are right, I should have first tried ol' reliable: "Turn it off and back on again" :facepalm: my bad

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 218 guests