ForNext
Only Do What Only You Can Do
205. escaped external command
Hyperpolyglot Interpreted Languages: PHP, Perl, Python, Ruby より (2012.05.08)
VBScript
JScript
Perl
$path = <>; chomp($path); system("ls", "-l", $path) == 0 or die "ls failed";
PHP
$path = chop(fgets(STDIN)); $safe = escapeshellarg($path); system("ls -l " . $safe, $retval); if ($retval) { throw new Exception("ls failed"); }
Python
import subprocess cmd = ['ls', '-l', '/tmp'] if subprocess.call(cmd): raise Exception('ls failed')
Ruby
path = gets path.chomp! unless system("ls", "-l", path) raise "ls failed" end