2013-11-01 1 views
0

나는 다음과 같이 명령을 실행, 동적 명령 문자열을 (펄 스크립트를 호출) 구축 PHP 스크립트를 가지고 : 나는 것을 생각 실패를 얻고있다PHP는 shell_exec() 보간

$cmd_string = "perl $pushFile"; 
    foreach($cmd_args AS $argName => $arg){ 
     $cmd_string .= ' --' . $argName . '="' . $arg . '"'; 
    } 
    $output = shell_exec('export PERL5LIB=/mnt/path/to/custom:$PERL5LIB && ' . $cmd_string . ' 2>&1'); 

일부 인수의 보간으로 인해 발생합니다. 예를 들어, 인수 중 하나가 '246 + 8GT> -'이면 '246 8GT'로 변환되고 문자열은 종료되지 않는다는 오류가 발생합니다. 그러나 print_r $ cmd_string을 화면에 표시하고 명령 줄을 통해 실행하거나 $ cmd_string 변수에 복사하여 붙여 넣으면 제대로 실행됩니다. 나는 곤두박질 친다. 어떻게이 논증들이 제대로 전달되고 있는지 확인할 수 있습니까? 나는 이것을 시도했다 :

$output = shell_exec('export PERL5LIB=/mnt/path/to/custom:$PERL5LIB && ' . escapeshellcmd($cmd_string) . ' 2>&1'); 

그러나 같은 결과를 얻는다. 도움?

답변

0

작성한 후 컴 맨드 끈을 이스케이프 처리합니다.

이 시도 :

$cmd_string = "perl $pushFile"; 
foreach($cmd_args AS $argName => $arg){ 
    $cmd_string .= ' --' . $argName . '="' . escapeshellarg($arg) . '"'; 
} 
$output = shell_exec('export PERL5LIB=/mnt/path/to/custom:$PERL5LIB && ' . $cmd_string . ' 2>&1');