
shell_exec 함수를 사용하여 PHP에서 Shell 명령어를 실행하는 방법은 다음과 같습니다.
1. shell_exec 함수를 사용하여 Shell 명령어를 실행할 수 있습니다.
#hostingforum.kr
php
$result = shell_exec('명령어');
위의 코드에서 '명령어' 부분에 실제로 Shell 명령어를 입력하면 됩니다.
2. Shell 명령어를 실행한 결과를 가져올 수 있습니다.
#hostingforum.kr
php
$result = shell_exec('명령어');
echo $result;
위의 코드에서 shell_exec 함수의 결과를 변수 $result에 저장한 후 echo 함수를 사용하여 결과를 출력할 수 있습니다.
3. Shell 명령어를 실행한 결과를 파일에 저장할 수 있습니다.
#hostingforum.kr
php
$result = shell_exec('명령어');
file_put_contents('파일명.txt', $result);
위의 코드에서 shell_exec 함수의 결과를 변수 $result에 저장한 후 file_put_contents 함수를 사용하여 결과를 파일에 저장할 수 있습니다.
4. Shell 명령어를 실행한 결과를 JSON 형식으로 변환할 수 있습니다.
#hostingforum.kr
php
$result = shell_exec('명령어');
$result = json_encode(json_decode($result, true));
echo $result;
위의 코드에서 shell_exec 함수의 결과를 변수 $result에 저장한 후 json_encode 함수를 사용하여 결과를 JSON 형식으로 변환할 수 있습니다.
5. Shell 명령어를 실행한 결과를 배열 형식으로 변환할 수 있습니다.
#hostingforum.kr
php
$result = shell_exec('명령어');
$result = explode("n", $result);
$result = array_map('trim', $result);
echo $result;
위의 코드에서 shell_exec 함수의 결과를 변수 $result에 저장한 후 explode 함수와 array_map 함수를 사용하여 결과를 배열 형식으로 변환할 수 있습니다.
2025-06-25 10:04