JesseTG JesseTG - 1 year ago 74
Bash Question

How to pass a script to a Windows 8 Vagrant box from the Mac command line?

I'm running a Windows 8.1 guest on a Mac OSX 10.11 host, via Vagrant. I want to pass in a script to this guest via command-line. If the guest were Unix-based, I could just do

vagrant ssh -c "$THE_SCRIPT" my-unix-box
and call it a day. When I try for the Windows guest, I'm told that the command
does not exist.

However, I can
vagrant ssh
into the Windows guest without specifying a command just fine. The resulting shell is
, not PowerShell or Bash or similar.

How can I execute a script on a guest Windows Vagrant box (from an OS X host) by passing it in on the command line? Vagrantfile configuration, guest software to install, or similar. I'm not picky about which shell ultimately runs my script.

Answer Source

It turns out you can pass the script to vagrant with double-dash separation, like so:


vagrant ssh windowsBox -- "$WINDOWS_THINGS"

In my case, this will run the contents of WINDOWS_THINGS as a cmd script. I guess the interpreter used depends on the underlying box, but whatever the case this solved my problem. Someone on IRC suggested this to me, and unfortunately I don't remember their name. But, if you're reading this, thank you!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download