in reply to Re^2: quoting/escaping file names
in thread quoting/escaping file names
Avoid the shell.
use warnings; use strict; use IPC::System::Simple 'capturex'; while (my $fn=<DATA>) { chomp($fn); $fn=~s/\\n/\n/g; # test filenames with newlines print "Filename: <<<$fn>>>\n"; # Method 1: capturex my $m1 = capturex('echo','-n',$fn); print "capturex: ", $m1 eq $fn ? "PASS" : "FAIL <<<$fn>>>", "\n"; # Method 2: piped open open my $pipe, '-|', 'echo', '-n', $fn or die $!; my $m2 = do { local $/; <$pipe> }; close $pipe or die $! ? $! : "\$?=$?"; print "open: ", $m2 eq $fn ? "PASS" : "FAIL <<<$fn>>>", "\n"; } __DATA__ $vaa it's not.txt /mnt1/$Recycle.Bin/S-1-5-21-3093161954-3198/$I7QM78L.pdf /tmp/File Wasn't found.txt ! @ # $ % ^ & * ( - + = { ] | \ : ; " ' < , . / ? ~ ` filename\nwith\newlines
All PASS on my system (Linux).
|
|---|