in reply to What is wrong with this code?

While only obliquely involved, Use strict and warnings.

Also, when running system commands on Win32, you have to quote paths in spaces. If I couldn't use any of the wonderful perl faculties to get a list of items in a folder, I'd have written $t = 'dir "C:\ProgramData\Test1\Test Folder"';, or renamed my target to not have spaces in it. :)

Replies are listed 'Best First'.
Re^2: What is wrong with this code?
by LanX (Saint) on Sep 08, 2014 at 13:21 UTC
    Good catch! :)

    ... but shouldn't the failing path (ie w/o " Folder") be shown in the error msg ? At least in $! ?

    I have currently no win system to test..

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      That would be the sane thing to do. On Windows 8:
      C:\>perl -v This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x +86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2012, Larry Wall Binary build 1603 [296746] provided by ActiveState http://www.ActiveSt +ate.com Built Mar 13 2013 11:29:21 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. C:\>perl -e "print `dir \C:\Program Files`; print \"\nerror: $!\n\" " File Not Found Volume in drive C is Windows8_OS Volume Serial Number is 78A2-8234 Directory of C:\ Directory of C:\ error: C:\>perl -e "print `dir \"C:\Program Files\"`" Volume in drive C is Windows8_OS Volume Serial Number is 78A2-8234 Directory of C:\Program Files 07/08/2014 09:31 AM <DIR> . 07/08/2014 09:31 AM <DIR> .. [redacted directory list] 0 File(s) 0 bytes 45 Dir(s) 137,746,575,360 bytes free C:\>

      Windows 7 does much the same.

      But you do bring to mind a good point: Is perl in the path?