{"id":4939,"date":"2025-04-18T11:36:53","date_gmt":"2025-04-18T10:36:53","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=4939"},"modified":"2025-04-18T11:54:05","modified_gmt":"2025-04-18T10:54:05","slug":"command-line","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/command-line\/command-line","title":{"rendered":"Command line"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Executing command line from PHP<\/h4>\n\n\n\n<p>Use shell_exec() or exec(). shell_exec() is typically more useful, because it returns all of the output, whereas exec() only retuns a single line.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Check shell_exec() exists<\/h4>\n\n\n\n<p>You can find its been disabled in php.ini for instance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  if(!function_exists('shell_exec'))\n    echo('shell_exec() is not available. Please check your PHP configuration.');<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Running a script with shell_exec()<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  exec(\"\/usr\/bin\/python3 $PathToScript $ProcessArguments\" . \" 2>&amp;1\", $Output, $Status);    \/\/The  \" 2>&amp;1\" part captures any error messages and puts them in the $Output array as well\n  if ($Status === 0)\n  {\n    \/\/----- SUCCESS -----\n    echo \"Output from Python script:&lt;br>\";\n    foreach ($Output as $Line)\n    {\n      echo($Line . \"&lt;br>);\n\n    }\n  }\n    \/\/----- AN ERROR OCCURED -----\n    echo \"Error executing script ($Status).&lt;br>\";\n    foreach ($Output as $Line)\n    {\n      echo($Line . \"&lt;br>);\n\n    }\n  }<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Executing command line from PHP Use shell_exec() or exec(). shell_exec() is typically more useful, because it returns all of the output, whereas exec() only retuns a single line. Check shell_exec() exists You can find its been disabled in php.ini for instance. Running a script with shell_exec()<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[374],"tags":[],"class_list":["post-4939","post","type-post","status-publish","format-standard","hentry","category-command-line"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4939","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=4939"}],"version-history":[{"count":5,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4939\/revisions"}],"predecessor-version":[{"id":4946,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4939\/revisions\/4946"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=4939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=4939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=4939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}