Reputation: 63
After installing Chef on windows, I found some dos commands no longer work in Perl if they contain forward slashes. For example, running `dir /AD .`
in Perl will now give you some warning like dir: /AD: No such file or directory
. I know the forward slash points to the root of the current working directory of the chef-client process. But it is really annoying this affects Perl as well. Is there any way to fix this? Thanks.
More info to clarify the issue:
I am using a fairly clean win7 64bit machine with ActivePerl 5.8.8 and Chef client 11.12.2-1. The issue is clearly related to the Chef installation. First, it is on and off when I install and uninstall the Chef client. Second, when I run dir /
, it lists contents of C:\opscode\chef\embedded folder.
Upvotes: 0
Views: 157
Reputation: 35198
Chef
isn't causing any problems. My system responds the same to the command: my @dirs = `dir /AD .`
. It treats /AD
as a directory instead of a flag throwing the same error message "dir: /AD: No such file or directory"
before returning all of the files in the current directory.
Using mob's comment solution of my @dirs = `cmd /C dir /AD .`
fixes the issue and returns the list of directories as desired.
However, the best method to solve this issue is just to make your perl code cross-platform compatible by not relying on OS specific builtins. For example, getting the list of directories in the cwd is easily done using the following:
my @dirs = grep -d, <*>;
Update
I'm running Strawberry perl 5.18.2 on Windows 7 x64
C:\>perl -v
This is perl 5, version 18, subversion 2 (v5.18.2) built for MSWin32-x64-multi-thread
Given what you've shared about the scope of the task, I think that mob's solution is probably your best bet. Yes, it'd be a pain to have to replace all of those backtick ``
and qx()
calls, but I don't foresee a better option. Good luck figuring out if/how Chef is causing the issue. Don't have anything else to add for now.
Upvotes: 3