Ask Your Question

Puppet Windows run two commands in one line

asked 2013-07-26 15:11:19 -0600

louis gravatar image


I am trying to run the following code.

 exec { 'install-service':
    command   => "cmd.exe /k 'cd D:\\${short_host}\\bin && service.install.bat'",
    logoutput => true,
    unless    => 'cmd.exe /c "sc query WindowsService"'

Where the short_host is a facter variable and service.install.bat just creates the windows service.

Notice: /Stage[main]/Teamcityagent/Exec[install-service]/returns: ''cd' is not recognized as an internal or external command,
Notice: /Stage[main]/Teamcityagent/Exec[install-service]/returns: operable program or batch file.
Notice: /Stage[main]/Teamcityagent/Exec[install-service]/returns:
Notice: /Stage[main]/Teamcityagent/Exec[install-service]/returns: C:\Program Files (x86)\Puppet Labs\Puppet Enterprise\bin>
Notice ...
edit retag flag offensive close merge delete


Do you have to cd to the directory before executing the .bat script, or can you call it directly as "D:\\{$short_host}\\bin\\service.install.bat"? If you have to ...(more)

GregLarkin gravatar imageGregLarkin ( 2013-07-29 13:15:39 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-07-29 14:18:01 -0600

louis gravatar image

I solved the issue by using cwd

  exec { 'install-service':
    command   => "cmd.exe /c service.install.bat",
    logoutput => true,
    cwd       => "D:\\${short_host}\\bin",
    unless    => 'cmd.exe /c "sc query WindowsService"',
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-07-26 15:11:19 -0600

Seen: 3,311 times

Last updated: Jul 29 '13