Directory with Spaces is not working

Hi,

I am able to copy file to a directory with space (TomEE 1.6_OpenText-APS) but as per the below link they said “chef in microsoft windows you cannot copy file to a dir with space” https://docs.chef.io/windows.html#spaces-and-directories

    Recipe: EPS::tomee
      * template[F:\TomEE 1.6_OpenText-APS\conf\tomee.xml] action create[2017-01-11T09:57:38+00:00] INFO: Processing template[F:\TomEE 1.6_OpenText-APS\conf\tomee.xml] action create (EPS::tomee line 19)
     (up to date)
    [2017-01-11T09:57:39+00:00] INFO: Chef Run complete in 3.003037 seconds

-But when i try to rename a directory with space(‘apache-tomcat-7.0.65’ to ‘Tomcat 7.0_Hybris-DataHub’) i am getting syntax error.

execute[rename tomcat directory] action run
[execute] The syntax of the command is incorrect.

================================================================================
Error executing action `run` on resource 'execute[rename tomcat directory]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of rename apache-tomcat-7.0.65 Tomcat 7.0_Hybris-DataHub ----
STDOUT:
STDERR: The syntax of the command is incorrect.
---- End output of rename apache-tomcat-7.0.65 Tomcat 7.0_Hybris-DataHub ----
Ran rename apache-tomcat-7.0.65 Tomcat 7.0_Hybris-DataHub returned 1

Not sure why it is behaving like this, i want to know the reason. Kindly help.

Hi,

Without the actual code of the execute resource it is close to impossible to find out what is going wrong here. I would guess you need to escape the spaces, but that is just a very wild guess.

You see in the error: The syntax is incorrect, it's because your command is actually:
rename param_1 param_2 param_3 where the commands takes only 2 parameters.
You have to quote the directory names to get a command line like rename "dir1" "dir2".

In a recipe this would be something along the line:

execute 'rename tomcat directory' do
  command %Q(rename "#{attribute_for_source}" "#{attribute for destinatinon}")
  guard "Whatever prevent this execute"
end

The %Q() syntax allow to use interpolationa nd doubles quotes without the headache of escaping them.
More details on this here: %Q, %q, %W, %w, %x, %r, %s | Simple Ruby on Rails

The quote from the doc is about the directory of chef itself, as a bunch of libraries won't be found if you install chef under a directory with spaces.

Usually under Windows its always better to avoid spaces in directories name, this beg to break scripts or others things, I'd recommend using _ instead of spaces in directory name.

Thank you friends,I am able to resolve this issue :slight_smile:

one more question:
I want to run chef-client remotely without logging into node and display console output (dont want to use knife-ssh), any idea how to do it ??

Thanks
vagga

You can use this command
knife winrm “10.164.1.89” “chef-client -o ‘recipe[cookbook_name::default@0.1.0]’” -m -x administrator -P “password”

Thanks sunil, its working :slight_smile:

Here logs showing info, i am looking for detailed logs because my cookbooks have some bat scripts that need to be executed on node, i want to know what each cmd in bat script is doing (like when i execute the chef-client on node directly).

Thanks,
Umesha