Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Command Prompt, Incompatibility?



  • Please log in to reply
4 replies to this topic
Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

I am terribly baffled by using cmd.exe (or %ComSpec%, or manually defining it as C:\Windows\system32\cmd.exe) with the Run command. Nothing visually appears if I were to use RunAs (no administrative prompt, though I do have UAC enabled, so confused on that).

 

But I would not expect that I need to run it as an administrator, because:

 

If I manually launch Command Prompt, I can do what I need. I get errors from what I input if I use AHK to launch the CMD, even if I manually type in the commands into the Command Prompt.

 

I just installed livestreamer from http://docs.livestreamer.io/cli.htmlto work around the no-HTML5 (for firefox) problem that Twitch has, as I got rid of Flash.

 

If I pass the command livestreamer twitch.tv/360chrism into the script in a manually launched CMD window, everything works.

 

But if I pass it into an AHK-launched cmd.exe, it tells me "'livestreamer' is not recognized as an internal or external command, operable program or batch file."

 

Why is that? I do notice that in the AHK-launched cmd.exe, the window title is C:\Windows\system32\cmd.exe whereas a manual launch has the window title Command Prompt.

 

Anyway to resolve this issue so that I can automate the command line process to easily launch my favorite streamers?

 

---

 

Edit: This is interesting. If I launch the Run dialog through AHK and then use that to launch the cmd.exe, it totally works. Here's some sample working code:

 

^0::
run, explorer.exe Shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}
WinWait, Run ahk_exe explorer.exe ahk_class #32770
SendInput cmd.exe{Enter}
WinWait, ahk_exe cmd.exe
SendInput livestreamer twitch.tv/360chrism source{Enter}
return

 

 

Thanks to this post by voltorn for the instructions for running the Run dialog inside the AHK run command: http://www.autohotke...ialog/?p=699272



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
If you're using AutoHotkey 32-bit, try C:\Windows\SysNative\cmd.exe or switching to 64-bit.

Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

I am on 64 bit Unicode AHK, v1.1.21.03. Regardless I'll still give the SysNative a shot just in case.

 

Oh, OS is also 8.1 in case that might make a difference.

 

In the past I've used the command prompt successfully by calling a .exe inside the prompt to return values, but that was on Vista. In that code I used a Run, cmd.exe,,Hide. The difference I suppose is that that example was a .exe, while what I'm trying with livestreamer does not seem to use a .exe. Will see if there is a .exe I can call.

 

Edit: I did find the .exe I can call. Unsurprisingly it's livestreamer.exe. However, it only works with a manually launched Command Prompt. Otherwise it's unrecognized. About to try a full directory call to it just in case.

 

Edit, if I go through this process:

cd C:\Program Files (x86)\Livestreamer{Enter}
livestreamer.exe{Enter}

Or

cd C:\Program Files(x86)\Livestreamer{Enter}
livestreamer twitch.tv/360chrism

It is a recognized process and totally works.

 

But if I manually launch the CMD, I don't need to navigate folders to use that livestreamer twitch.tv/360chrism command. Manually launching brings me to the C:\Users\Exaskryz directory, and even manually navigating to that with an AHK-launched Command Prompt does not make the livestreamer command recognizable.

 

---

 

Still haven't tried the SysNative. That directory isn't on my system,



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
✓  Best Answer

Try set path from a manually launched CMD and one launched by AutoHotkey, and compare the values to see whether any directories are missing:

C:\>set path
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Git\cmd;...etc.
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

Omitting the directory will work ONLY if the program's directory and filename extension are listed there or the program is in the working directory.

 

Of course, you could always use the full path, or set the working directory of CMD when launching it with the Run command.

 

"SysNative" isn't a real directory, and is only valid from a 32-bit program on a 64-bit OS.  For 32-bit programs, it refers to the real System32 directory, whereas "System32" is redirected to SysWow64.



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Alrighty!

 

Looks like a manually launched CMD includes inside the reported directories from the set path command: C:\Program Files (x86)\Livestreamer

 

Every other directory is in both a manually launched and an AHK launched CMD. AHK simply doesn't recognize that Livestreamer directory.

 

Is there any reason that AHK doesn't recognize it? Probably because of the way the authors of Livestreamer (which is open source if you were curious enough to dig around in it; I'm not expecting you to) added their path?

 

Oooh, would restarting my computer be necessary... Or, (Solution:) killing all ahk programs and having them reload? I'm gonna try that one.

 

Ah! Got it.

 

Thank you Lexikos for information regarding Set Path. That clued me into the idea that my always-running AHK scripts needed to be killed for the update to the command prompt's paths to be recognized - it appeared that running programs, or at least AHK, would have a cache of sorts for the paths they recognize and completely restarting them is necessary for them to update.

 

Now I can skip the run dialog and here's some code in case anyone stumbled upon this thread looking for a livestreamer speed-up for AHK. It could probably be improved quite a bit (notably if I can work out a way to define a certain number of streamers to check if they're online, and the first found has their stream launched).

#0::
IfWinExist, fd://0 - VLC media player
{
MsgBox Livestreamer only supports one stream at a time ; may not be true if you change some options in the configuration file
return
}
InputBox, streamer, Select Streamer, % "Which streamer would you like to watch?`n" (streamer?"Previously watched " streamer:"")
If (!streamer || ErrorLevel)
return
DetectHiddenWindows, On
Run, cmd.exe,,hide,twitchcmd
WinWait, ahk_pid %twitchcmd%
ControlSend,,livestreamer twitch.tv/%streamer% best{Enter}, ahk_pid %twitchcmd%
WinWaitClose, fd://0 - VLC media player
WinClose, ahk_pid %twitchcmd%
DetectHiddenWindows, Off
return