emyl / vagrant-triggers

Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.
MIT License
546 stars 35 forks source link

Cannot use builtin commands (e.g. "if") on Windows hosts #43

Closed mbrodala closed 8 years ago

mbrodala commented 9 years ago

To reduce the noise when trying to re-mount an existing share drive (see #27), I'd like to make it conditional. This is what I tried:

config.trigger.after :up do
  # Mount network share after startup
  run "if not exist Z: net use /y Z: \\\\192.168.33.10\\webroot"
end

This yields the following error:

The executable "if" Vagrant is trying to trigger was not found. If you know it is not in the PATH, please specify its absolute path using the :append_to_path option.

Sure, if is no command (executable) but a builtin. Thus I tried with a sub-process:

config.trigger.after :up do
  # Mount network share after startup
  run 'cmd /c "if not exist Z: net use /y Z: \\\\192.168.33.10\\webroot"'
end

But this gives me the following error:

The command "cmd /c "if not exist Z: net use /y Z: \192.168.33.10\webroot"" returned a failed exit code. The error output is shown below: Syntax error.

Executing cmd /c "if not exist Z: net use /y Z: \\192.168.33.10\webroot" within a command prompt works perfectly fine though.

Any idea what's wrong here?

colegatron commented 8 years ago

Other user reported issues using "run" and was successful using "system" instead. Maybe it helps.

mbrodala commented 8 years ago

You mean like in #53? I'll give it a try.

mbrodala commented 8 years ago

Works flawlessly, thanks for the hint. :-)

This is what I'm using now:

config.trigger.after :up do
  # Mount network share after startup
  system "if not exist Z: net use /y Z: \\\\192.168.33.10\\webroot"
end
jerturowetz commented 6 years ago

I stumbled on this issue trying to resolve using 'cd' in an inline script.

The executable "cd" Vagrant is trying to trigger
was not found. If you know it is not in the PATH, please
specify its absolute path using the :append_to_path option.

I'm wondering how triggers chooses which shell it uses and, if we could change this, if this might resolve the issue for us Windows users. (All speculative as I've only just started leaning ruby specifically in order to manipulate vagrant and my understanding of how triggers works is extremely shady as I pour through the code.)