Запуск сценария autohotkey с помощью vagrant предоставления завершился неудачно - PullRequest
0 голосов
/ 10 февраля 2020

Я пытаюсь использовать AHK с помощью сценария Vagrant Provision ps1

Соответствующая часть Vagrantfile:

config.vm.provision "shell", path: "scripts/set-up-byte.ps1", privileged: false

Сценарий set-up-byte.ps1:

Invoke-Item "C:\vagrant\promontech\setup_byte.ahk"

Я пытался использовать несколько разных стилей исполнения (&, простой вызов скрипта, ссылка на AutoHotKey.exe и передача сценария ahk в качестве параметра), но все они приводят к одному и тому же странному поведению. Трудно подвести итог, поэтому я позволю описать этот GIF для меня.

gif showing issue: script runs, then a split second panel flashes in windows saying I will be signed out, then a logoff cancelled notification message shows up in the bottom right of windows.

Короче говоря, кажется, что положение делает что-то , но я не Знаешь что. Кажется, он пытается начать сеанс windows, а затем отменить его. Но он не запускает скрипт. Если я запускаю точно такую ​​же команду из Гостевой системы, AutoHotKey срабатывает и работает отлично.

Я чувствую, что это некоторая проблема с моим пониманием сценариев предоставления vagrant, но документация vagrant до сих пор не помогла.

Запуск сценария с VAGRANT_LOG=debug vagrant provision не предоставляет никакой дополнительной информации:

DEBUG winrmshell: File /tmp/vagrant-shell.ps1 is up to date, skipping
DEBUG winrmshell: No remote files to extract, skipping
DEBUG winrmshell: Uploaded 1 items dirty_check: (0m0.53s) stream_files: (0m0.00s) extract: (0m0.00s)
 INFO interface: detail: Running: scripts/set-up-byte.ps1 as c:\tmp\vagrant-shell.ps1
 INFO interface: detail:     update: Running: scripts/set-up-byte.ps1 as c:\tmp\vagrant-shell.ps1
    update: Running: scripts/set-up-byte.ps1 as c:\tmp\vagrant-shell.ps1
DEBUG winrm: powershell executing:
powershell -ExecutionPolicy Bypass -OutputFormat Text -file "c:\tmp\vagrant-shell.ps1"
DEBUG winrmshell: [WinRM] opening remote shell on http://127.0.0.1:55985/wsman
DEBUG winrmshell: [WinRM] Endpoint doesn't support config request for MaxEnvelopsizekb
DEBUG winrmshell: [WinRM] Waiting for output...
DEBUG winrmshell: [WinRM] Processing output
DEBUG winrmshell: [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x00000001030ef2f0 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><Version N=\"protocolversion\">2.3</Version><Version N=\"PSVersion\">2.0</Version><Version N=\"SerializationVersion\">1.1.0.1</Version></MS></Obj>", @destination=1, @type=65538, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000">
DEBUG winrmshell: [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x00000001030ee378 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><Obj N=\"ApplicationPrivateData\" RefId=\"1\"><TN RefId=\"0\"><T>System.Management.Automation.PSPrimitiveDictionary</T><T>System.Collections.Hashtable</T><T>System.Object</T></TN><DCT><En><S N=\"Key\">BreakAll</S><B N=\"Value\">false</B></En><En><S N=\"Key\">DebugStop</S><B N=\"Value\">false</B></En><En><S N=\"Key\">UnhandledBreakpointMode</S><I32 N=\"Value\">1</I32></En><En><S N=\"Key\">PSVersionTable</S><Obj N=\"Value\" RefId=\"2\"><TNRef RefId=\"0\" /><DCT><En><S N=\"Key\">PSVersion</S><Version N=\"Value\">5.1.17763.771</Version></En><En><S N=\"Key\">PSEdition</S><S N=\"Value\">Desktop</S></En><En><S N=\"Key\">PSCompatibleVersions</S><Obj N=\"Value\" RefId=\"3\"><TN RefId=\"1\"><T>System.Version[]</T><T>System.Array</T><T>System.Object</T></TN><LST><Version>1.0</Version><Version>2.0</Version><Version>3.0</Version><Version>4.0</Version><Version>5.0</Version><Version>5.1.17763.771</Version></LST></Obj></En><En><S N=\"Key\">CLRVersion</S><Version N=\"Value\">4.0.30319.42000</Version></En><En><S N=\"Key\">BuildVersion</S><Version N=\"Value\">10.0.17763.771</Version></En><En><S N=\"Key\">WSManStackVersion</S><Version N=\"Value\">3.0</Version></En><En><S N=\"Key\">PSRemotingProtocolVersion</S><Version N=\"Value\">2.3</Version></En><En><S N=\"Key\">SerializationVersion</S><Version N=\"Value\">1.1.0.1</Version></En></DCT></Obj></En><En><S N=\"Key\">DebugMode</S><I32 N=\"Value\">1</I32></En><En><S N=\"Key\">DebugBreakpointCount</S><I32 N=\"Value\">0</I32></En></DCT></Obj></MS></Obj>", @destination=1, @type=135177, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000">
DEBUG winrmshell: [WinRM] Waiting for output...
DEBUG winrmshell: [WinRM] Processing output
DEBUG winrmshell: [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x0000000102b037d8 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I32 N=\"RunspaceState\">2</I32></MS></Obj>", @destination=1, @type=135173, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000">
DEBUG winrmshell: [WinRM] remote shell created with shell_id: 5819A8FC-B762-44AE-936A-F95F67C89A5A
DEBUG winrmshell: [WinRM] Command created for powershell -ExecutionPolicy Bypass -OutputFormat Text -file "c:\tmp\vagrant-shell.ps1"
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 90038593-1BB7-446A-8CF6-1042E7DBCC82
DEBUG winrmshell: [WinRM] creating command_id: 90038593-1BB7-446A-8CF6-1042E7DBCC82 on shell_id 5819A8FC-B762-44AE-936A-F95F67C89A5A
DEBUG winrmshell: [WinRM] Waiting for output...
DEBUG winrmshell: [WinRM] Processing output
 INFO interface: detail: VERBOSE: Performing the operation "Set Alias" on target "Name: nuget Value: C:\nuget.exe".
 INFO interface: detail:     update: VERBOSE: Performing the operation "Set Alias" on target "Name: nuget Value: C:\nuget.exe".

Я не добавил тег powershell, поскольку он не является проблемой с powershell. , но с исполнением АХК.


Редактировать 1:

Вот настройка, которая будет воспроизводить проблему.

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # uses https://github.com/StefanScherer/docker-windows-box, you'll need to build it yourself
  config.vm.box = "../../packer-windows/windows_2019_virtualbox.box"
  config.vm.communicator = "winrm"

  config.vm.provider "virtualbox" do |v|
    v.gui = true
    v.customize ["modifyvm", :id, "--memory", 2048]
    v.customize ["modifyvm", :id, "--cpus", 2]
    v.customize ["modifyvm", :id, "--vram", 128]
    v.customize ["modifyvm", :id, "--clipboard-mode", "bidirectional"]
    v.customize ["modifyvm", :id, "--accelerate3d", "on"]
    v.customize ["modifyvm", :id, "--accelerate2dvideo", "on"]
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    v.linked_clone = true if Vagrant::VERSION =~ /^1.8/
  end

  config.vm.provision "shell", path: "test.ps1", privileged: false

end

test.ps1

# install chocolatey
iex (wget 'https://chocolatey.org/install.ps1' -UseBasicParsing)
choco feature disable --name showDownloadProgress
choco install autohotkey -y
# run script
Invoke-Item "C:\vagrant\test.ahk"

test.ahk

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

MsgBox, Test
...