in reply to What is wrong with this code?

The first step would have been to, say:

print "T is '$t'\n";

In other words, “never assume” that you actually know what command-string is being executed.   Tell Perl to print the content of the string, so that you can be certain that it is what you expect it to be.   Then, using the command-line shell, chase down any remaining issues.

In this case, I daresay that the real problem is that there is a space in the path.   So, if you copy-and-paste the literal string into the command line shell of Windows, you will find that it ... doesn’t work there, either.   The shell sees the filename Test and has no idea what to do with “the next word of the command, which is Folder.”   Oops.   You need to present a command which encloses the pathname in double quotes.   Say ...

$t = "dir \"C:\\ProgramData\\Test1\\Test Folder\""

Notice how I have used \" to specify the inclusion of a literal quote-mark.   So, the command that is presented will be:

dir "C:\\ProgramData\\Test1\\Test Folder"
... which the shell will now parse correctly.

Replies are listed 'Best First'.
Re^2: What is wrong with this code?
by Anonymous Monk on Sep 09, 2014 at 14:24 UTC

    The first step would have been to, say:

    print "T is '$t'\n";

    In other words, "never assume" that you actually know what command-string is being executed. ...

    $t = "dir \"C:\\ProgramData\\Test1\\Test Folder\""

    ... So, the command that is presented will be:

    dir "C:\\ProgramData\\Test1\\Test Folder"
    $ perl -wMstrict my $t = "dir \"C:\\ProgramData\\Test1\\Test Folder\""; print "T is '$t'\n"; __END__ T is 'dir "C:\ProgramData\Test1\Test Folder"'