{"id":675,"date":"2025-06-11T12:37:39","date_gmt":"2025-06-11T04:37:39","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/xtywj\/675.html"},"modified":"2025-06-11T12:37:39","modified_gmt":"2025-06-11T04:37:39","slug":"php-%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8shell_exec%e5%87%bd%e6%95%b0%e6%89%a7%e8%a1%8cshell%e5%91%bd%e4%bb%a4","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/675.html","title":{"rendered":"PHP: \u5982\u4f55\u4f7f\u7528shell_exec()\u51fd\u6570\u6267\u884cshell\u547d\u4ee4"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p><code>shell_exec()<\/code> &#26159; PHP &#20013;&#30340;&#19968;&#20010;&#20869;&#32622;&#20989;&#25968;&#65292;&#29992;&#20110;&#22312;&#26381;&#21153;&#22120;&#19978;&#25191;&#34892; shell &#21629;&#20196;&#24182;&#36820;&#22238;&#20854;&#36755;&#20986;&#12290;&#36825;&#20010;&#20989;&#25968;&#38750;&#24120;&#24378;&#22823;&#65292;&#21487;&#20197;&#29992;&#26469;&#33258;&#21160;&#21270;&#21508;&#31181;&#25805;&#20316;&#65292;&#22914;&#25991;&#20214;&#22788;&#29702;&#12289;&#31995;&#32479;&#31649;&#29702;&#31561;&#12290;<\/p>\n<p>&#20197;&#19979;&#26159;&#22914;&#20309;&#20351;&#29992; <code>shell_exec()<\/code> &#20989;&#25968;&#25191;&#34892; shell &#21629;&#20196;&#30340;&#31034;&#20363;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\n\/\/ &#35201;&#25191;&#34892;&#30340; shell &#21629;&#20196;\n$command = 'ls -l';\n\n\/\/ &#20351;&#29992; shell_exec() &#25191;&#34892;&#21629;&#20196;&#24182;&#33719;&#21462;&#36755;&#20986;\n$output = shell_exec($command);\n\n\/\/ &#36755;&#20986;&#32467;&#26524;\necho $output;\n?&gt;<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#31034;&#20363;&#20013;&#65292;&#25105;&#20204;&#25191;&#34892;&#20102; <code>ls -l<\/code> &#21629;&#20196;&#65292;&#35813;&#21629;&#20196;&#21015;&#20986;&#24403;&#21069;&#30446;&#24405;&#20013;&#30340;&#25152;&#26377;&#25991;&#20214;&#21644;&#23376;&#30446;&#24405;&#65292;&#24182;&#20197;&#38271;&#26684;&#24335;&#26174;&#31034;&#12290;<code>shell_exec()<\/code> &#20989;&#25968;&#23558;&#36820;&#22238;&#36825;&#20010;&#21629;&#20196;&#30340;&#36755;&#20986;&#65292;&#28982;&#21518;&#25105;&#20204;&#23558;&#23427;&#25171;&#21360;&#21040;&#23631;&#24149;&#19978;&#12290;<\/p>\n<h3>&#31034;&#20363;&#20195;&#30721;&#35814;&#32454;&#27493;&#39588;<\/h3>\n<ol>\n<li>\n<p><strong>&#23450;&#20041;&#35201;&#25191;&#34892;&#30340; shell &#21629;&#20196;<\/strong>&#65306;<\/p>\n<pre><code class=\"language-php\">$command = 'ls -l';<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>&#20351;&#29992; <code>shell_exec()<\/code> &#25191;&#34892;&#21629;&#20196;&#24182;&#33719;&#21462;&#36755;&#20986;<\/strong>&#65306;<\/p>\n<pre><code class=\"language-php\">$output = shell_exec($command);<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>&#36755;&#20986;&#32467;&#26524;<\/strong>&#65306;<\/p>\n<pre><code class=\"language-php\">echo $output;<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>&#27880;&#24847;&#20107;&#39033;<\/h3>\n<ul>\n<li><strong>&#23433;&#20840;&#24615;<\/strong>&#65306;<code>shell_exec()<\/code> &#21487;&#33021;&#20250;&#24102;&#26469;&#23433;&#20840;&#39118;&#38505;&#65292;&#22240;&#20026;&#23427;&#20801;&#35768;&#20320;&#22312;&#33050;&#26412;&#20013;&#25191;&#34892;&#20219;&#24847; shell &#21629;&#20196;&#12290;&#30830;&#20445;&#21482;&#25191;&#34892;&#21487;&#20449;&#30340;&#21629;&#20196;&#65292;&#24182;&#19988;&#19981;&#35201;&#22312;&#29983;&#20135;&#29615;&#22659;&#20013;&#36816;&#34892;&#26410;&#39564;&#35777;&#30340;&#21629;&#20196;&#12290;<\/li>\n<li>\n<p><strong>&#38169;&#35823;&#22788;&#29702;<\/strong>&#65306;&#22312;&#23454;&#38469;&#24212;&#29992;&#20013;&#65292;&#24314;&#35758;&#28155;&#21152;&#38169;&#35823;&#22788;&#29702;&#26469;&#25429;&#33719;&#21487;&#33021;&#30340;&#38169;&#35823;&#20449;&#24687;&#65292;&#20363;&#22914;&#20351;&#29992; <code>error_get_last()<\/code> &#20989;&#25968;&#26469;&#26816;&#26597;&#26159;&#21542;&#26377;&#38169;&#35823;&#21457;&#29983;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\n\/\/ &#35201;&#25191;&#34892;&#30340; shell &#21629;&#20196;\n$command = 'ls -l';\n\n\/\/ &#20351;&#29992; shell_exec() &#25191;&#34892;&#21629;&#20196;&#24182;&#33719;&#21462;&#36755;&#20986;\n$output = shell_exec($command);\n\n\/\/ &#26816;&#26597;&#26159;&#21542;&#26377;&#38169;&#35823;\nif ($output === false) {\n  $error = error_get_last();\n  echo \"Error executing command: \" . $error['message'];\n} else {\n  \/\/ &#36755;&#20986;&#32467;&#26524;\n  echo $output;\n}\n?&gt;<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>&#36890;&#36807;&#36825;&#20123;&#27493;&#39588;&#65292;&#20320;&#21487;&#20197;&#36731;&#26494;&#22320;&#22312; PHP &#20013;&#20351;&#29992; <code>shell_exec()<\/code> &#20989;&#25968;&#25191;&#34892; shell &#21629;&#20196;&#65292;&#24182;&#26681;&#25454;&#38656;&#35201;&#22788;&#29702;&#20854;&#36755;&#20986;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h2>&#20171;&#32461;<\/h2><p>&#22312;&#26381;&#21153;&#22120;&#31471;&#33050;&#26412;&#30340;&#19990;&#30028;&#37324;&#65292;PHP &#26159;&#19968;&#20010;&#24378;&#22823;&#30340;&#24037;&#20855;&#65292;&#36890;&#24120;&#19982;&#23427;&#25152;&#22312;&#30340;&#31995;&#32479;&#36827;&#34892;&#20132;&#20114;&#12290;&#36890;&#36807;&#21644;&#24213;&#23618;&#25805;&#20316;&#31995;&#32479;&#20114;&#21160;&#21487;&#20197;&#20026;&#24212;&#29992;&#31243;&#24207;&#25552;&#20379;&#24378;&#22823;&#30340;&#21151;&#33021;&#12290;&#20854;&#20013;&#30340;&#19968;&#31181;&#25509;&#21475;&#23601;&#26159;&#25191;&#34892; shell &#21629;&#20196;&#12290;&#22312;&#36825;&#20010;&#25945;&#31243;&#20013;&#65292;&#25105;&#20204;&#23558;&#28145;&#20837;&#25506;&#35752;&#36825;&#20010;&#35805;&#39064;&#12290;<code>shell_exec()<\/code>&#22312;PHP&#20013;&#65292;&#26377;&#19968;&#20010;&#20989;&#25968;&#29992;&#20110;&#36890;&#36807;shell&#25191;&#34892;&#21629;&#20196;&#24182;&#30452;&#25509;&#20174;PHP&#25910;&#38598;&#23436;&#25972;&#30340;&#36755;&#20986;&#12290;<\/p><p>&#20808;&#20915;&#26465;&#20214;<\/p><p>&#23545;shell&#21629;&#20196;&#30340;&#29087;&#24713;&#24615;&#12290;<\/p><p>&#22522;&#26412;&#30340;PHP&#35821;&#27861;&#21644;&#20989;&#25968;&#30693;&#35782;<\/p><p>&#36816;&#34892;&#22312;&#26381;&#21153;&#22120;&#25110;&#26412;&#22320;&#24320;&#21457;&#29615;&#22659;&#20013;&#30340;PHP&#29615;&#22659;&#12290;<\/p><h2>&#29702;&#35299;<code>shell_exec()<\/code><\/h2><p>&#35821;&#27861;&#30340;<code>shell_exec()<\/code>&#26159;&#30340;&#65292;&#38750;&#24120;&#31616;&#21333;&#65306;<\/p><pre><code>string shell_exec ( string $cmd )<\/code><\/pre><p>&#35813;&#21151;&#33021;&#26377;&#19968;&#20010;&#21442;&#25968;&#65306;<code>$cmd<\/code>&#35831;&#25552;&#20379;&#20320;&#38656;&#35201;&#25191;&#34892;&#30340;&#21629;&#20196;&#34892;&#23383;&#31526;&#20018;&#65292;&#20197;&#20415;&#25105;&#23558;&#20854;&#36716;&#25442;&#20026;&#19968;&#20010;&#23383;&#31526;&#20018;&#24182;&#36820;&#22238;&#23436;&#25972;&#36755;&#20986;&#12290;<code>NULL<\/code>&#24403;&#21457;&#29983;&#38169;&#35823;&#25110;&#32773;&#21629;&#20196;&#27809;&#26377;&#36755;&#20986;&#26102;&#12290;<\/p><h2>&#23454;&#26045;<code>shell_exec()<\/code><\/h2><p>&#35753;&#25105;&#20204;&#20174;&#22522;&#26412;&#29992;&#27861;&#24320;&#22987;&#65306;<\/p><pre><code>$output = shell_exec('ls -lart');\necho $output;<\/code><\/pre><p>&#36825;&#23558;&#25353;&#35814;&#32454;&#12289;&#20498;&#24207;&#30340;&#26102;&#38388;&#39034;&#24207;&#21015;&#20986;&#24403;&#21069;&#30446;&#24405;&#20013;&#30340;&#25991;&#20214;&#12290;<\/p><h3>&#26368;&#20339;&#23454;&#36341;&#65306;&#32593;&#32476;&#23433;&#20840;<\/h3><p>&#22312;&#20351;&#29992;&#26102;&#65292;&#23433;&#20840;&#19981;&#24212;&#35813;&#34987;&#24403;&#20316;&#19968;&#20010;&#27425;&#35201;&#38382;&#39064;&#12290;<code>shell_exec()<\/code>&#65306;<\/p><p>&#32771;&#34385;&#20351;&#29992;&#23613;&#21487;&#33021;&#39640;&#30340;PHP&#20989;&#25968;&#32780;&#19981;&#26159;shell&#21629;&#20196;&#12290;<\/p><p>&#38480;&#21046;&#21487;&#20197;&#25191;&#34892;&#30340;&#21629;&#20196;&#12290;<\/p><p>&#22987;&#32456;&#39564;&#35777;&#21644;&#28165;&#29702;&#23558;&#20316;&#20026;shell&#21629;&#20196;&#30340;&#19968;&#37096;&#20998;&#30340;&#36755;&#20837;&#12290;<\/p><h2>&#38169;&#35823;&#22788;&#29702;&#21644;&#35786;&#26029;<\/h2><p><code>shell_exec()<\/code>&#19981;&#36820;&#22238;&#26631;&#20934;&#38169;&#35823;&#12290;&#35201;&#25429;&#33719;&#38169;&#35823;&#65292;&#21487;&#20197;&#23558;&#26631;&#20934;&#38169;&#35823;&#37325;&#23450;&#21521;&#21040;&#26631;&#20934;&#36755;&#20986;&#65306;<\/p><pre><code>$output = shell_exec('somecommand 2&gt;&amp;1');<\/code><\/pre><p>&#36825;&#23558;&#30830;&#20445;&#38169;&#35823;&#28040;&#24687;&#34987;&#25429;&#33719;&#22312;&#36755;&#20986;&#20013;&#12290;<\/p><h2>&#26367;&#20195;&#26041;&#26696;&#26159;<code>shell_exec()<\/code><\/h2><p>&#22914;&#26524;&#38656;&#35201;&#23545;&#25191;&#34892;&#36807;&#31243;&#36827;&#34892;&#26356;&#22810;&#30340;&#25511;&#21046;&#25110;&#32773;&#24819;&#35201;&#23454;&#26102;&#22788;&#29702;&#36807;&#31243;&#36755;&#20837;&#36755;&#20986;&#65292;&#21487;&#20197;&#32771;&#34385;&#20197;&#19979;&#21151;&#33021;&#65306;<\/p><p><code>proc_open()<\/code>&#25552;&#20379;&#20102;&#23545;&#36807;&#31243;&#25191;&#34892;&#30340;&#20840;&#38754;&#25511;&#21046;&#65292;&#21253;&#25324;&#26631;&#20934;&#36755;&#20837;&#27969;&#12289;&#26631;&#20934;&#36755;&#20986;&#27969;&#21644;&#26631;&#20934;&#38169;&#35823;&#27969;&#12290;<\/p><p><code>system()<\/code>&#25191;&#34892;&#19968;&#20010;&#24102;&#36755;&#20986;&#30340;shell&#21629;&#20196;&#24182;&#36820;&#22238;&#29366;&#24577;&#30721;&#12290;<\/p><p><code>passthru()<\/code>&#25191;&#34892;&#21629;&#20196;&#24182;&#30452;&#25509;&#23558;&#21407;&#22987;&#36755;&#20986;&#21457;&#36865;&#21040;&#27983;&#35272;&#22120;&#12290;<\/p><p><code>exec()<\/code>&#25191;&#34892;&#19968;&#20010;&#21333;&#20010;&#30340;shell&#21629;&#20196;&#65292;&#24182;&#21487;&#36873;&#22320;&#25910;&#38598;&#36755;&#20986;&#30340;&#26368;&#21518;&#19968;&#34892;&#12290;<\/p><h2>&#24120;&#35265;&#29992;&#20363;&#21644;&#31034;&#20363;<\/h2><p>&#38500;&#20102;&#21015;&#20986;&#25991;&#20214;&#65292;&#36825;&#37324;&#26159;&#22914;&#20309;&#20351;&#29992;&#30340;&#26041;&#27861;&#12290;<code>shell_exec()<\/code>&#23545;&#20110;&#26356;&#22797;&#26434;&#30340;&#20219;&#21153;&#65306;<\/p><h3>&#36816;&#34892;&#19968;&#20010;Python&#33050;&#26412;<\/h3><pre><code>$output = shell_exec('python \/path\/to\/script.py');<\/code><\/pre><h3>Pingning a Server<\/h3><pre><code>$domain = escapeshellarg('example.com'); \/\/$domain is now safe to use in the shell command\n$output = shell_exec('ping -c 4 ' . $domain);<\/code><\/pre><h2>&#32467;&#35770;&#12290;<\/h2><p>&#22312;&#26412;&#25945;&#31243;&#20013;&#65292;&#25105;&#20204;&#35752;&#35770;&#20102;<code>shell_exec()<\/code>&#22312;PHP&#20013;&#65292;&#21253;&#25324;&#20854;&#35821;&#27861;&#12289;&#20351;&#29992;&#26041;&#24335;&#12289;&#23433;&#20840;&#39038;&#34385;&#20197;&#21450;&#28508;&#22312;&#30340;&#26367;&#20195;&#26041;&#26696;&#12290;&#23613;&#31649;PHP&#26159;&#19968;&#20010;&#24378;&#22823;&#30340;&#24037;&#20855;&#65292;&#20294;&#22312;&#22788;&#29702;shell&#21629;&#20196;&#26102;&#22987;&#32456;&#24212;&#23558;&#23433;&#20840;&#24615;&#25918;&#22312;&#39318;&#20301;&#65292;&#24182;&#23613;&#21487;&#33021;&#21033;&#29992;PHP&#30340;&#39640;&#32423;&#21151;&#33021;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p><code>shell_exec()<\/code> &#26159; PHP &#20013;&#30340;&#19968;&#20010;&#20869;&#32622;&#20989;&#25968;&#65292;&#29992;&#20110;&#25191;&#34892; shell &#21629;&#20196;&#24182;&#36820;&#22238;&#32467;&#26524;&#12290;<\/p>\n<p>&#35201;&#20351;&#29992; <code>shell_exec()<\/code> &#20989;&#25968;&#65292;&#20320;&#38656;&#35201;&#25552;&#20379;&#20004;&#20010;&#21442;&#25968;&#65306;&#31532;&#19968;&#20010;&#26159;&#21629;&#20196;&#23383;&#31526;&#20018;&#65292;&#31532;&#20108;&#20010;&#26159;&#25991;&#20214;&#25551;&#36848;&#31526;&#65288;&#36890;&#24120;&#20026; 2&#65289;&#12290;&#36825;&#20010;&#25991;&#20214;&#25551;&#36848;&#31526;&#21487;&#20197;&#26159;&#26631;&#20934;&#36755;&#20986;&#65288;STDOUT&#65289;&#12289;&#26631;&#20934;&#36755;&#20837;&#65288;STDIN&#65289;&#25110;&#32773;&#26631;&#20934;&#38169;&#35823;&#65288;STDERR&#65289;&#12290;<\/p>\n<p>&#20363;&#22914;&#65292;&#22914;&#26524;&#20320;&#24819;&#35201;&#20174;&#32456;&#31471;&#25191;&#34892;&#19968;&#20010;&#21629;&#20196;&#65292;&#24182;&#23558;&#32467;&#26524;&#25171;&#21360;&#21040;&#25511;&#21046;&#21488;&#65292;&#20320;&#21487;&#20197;&#36825;&#26679;&#20570;&#65306;<\/p>\n<pre><code class=\"language-php\">$command = 'ls';\n$output = shell_exec($command);\necho $output;<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;<code>shell_exec()<\/code> &#34987;&#29992;&#26469;&#36816;&#34892; <code>ls<\/code> &#21629;&#20196;&#65292;&#28982;&#21518;&#23558;&#32467;&#26524;&#23384;&#20648;&#22312; <code>$output<\/code> &#21464;&#37327;&#20013;&#65292;&#26368;&#21518;&#23558;&#20854;&#25171;&#21360;&#20986;&#26469;&#12290;<\/p>\n<p>&#27880;&#24847;&#65306;&#34429;&#28982; <code>shell_exec()<\/code> &#22312;&#29702;&#35770;&#19978;&#25903;&#25345;&#20219;&#20309;&#31867;&#22411;&#30340; shell&#65288;&#22914; bash&#65289;&#65292;&#20294;&#22312;&#23454;&#38469;&#24212;&#29992;&#20013;&#65292;&#23427;&#26356;&#24120;&#34987;&#29992;&#20110;&#25191;&#34892; shell &#33050;&#26412;&#21644; shell &#21629;&#20196;&#12290;&#27492;&#22806;&#65292;<code>shell_exec()<\/code> &#19981;&#20250;&#22788;&#29702;&#20219;&#20309;&#29305;&#27530;&#23383;&#31526;&#65292;&#22240;&#27492;&#22914;&#26524;&#38656;&#35201;&#22788;&#29702;&#36825;&#20123;&#29305;&#27530;&#23383;&#31526;&#65292;&#21487;&#33021;&#38656;&#35201;&#20351;&#29992; <code>exec()<\/code> &#25110;&#32773;&#20854;&#20182;&#30340;&#33050;&#26412;&#25191;&#34892;&#26041;&#24335;&#12290;<\/p>\n<p>&#21478;&#22806;&#65292;&#30830;&#20445;&#20320;&#22312;&#23433;&#20840;&#30340;&#29615;&#22659;&#20013;&#20351;&#29992; <code>shell_exec()<\/code>&#65292;&#22240;&#20026;&#23427;&#21487;&#33021;&#20250;&#23548;&#33268;&#25935;&#24863;&#20449;&#24687;&#27844;&#38706;&#25110;&#20854;&#20182;&#23433;&#20840;&#38382;&#39064;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; shell_exec() &#26159; PHP &#20013;&#30340;&#19968;&#20010;&#20869;&#32622;&#20989;&#25968;&#65292;&#29992;&#20110;&#22312;&#26381;&#038;#..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[42],"tuisongtax":[],"class_list":["post-675","my1js","type-my1js","status-publish","hentry","my1js2nav-xtywj"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=675"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=675"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=675"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}