{"id":4738,"date":"2025-01-30T15:14:00","date_gmt":"2025-01-30T15:14:00","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=4738"},"modified":"2025-01-30T15:16:01","modified_gmt":"2025-01-30T15:16:01","slug":"running-scripts-and-executibles","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/files\/running-scripts-and-executibles","title":{"rendered":"Running scripts and executibles"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\" id=\"block-36c3c069-ee9f-4360-bb64-41afb36bc47f\">Running a Python script<\/h4>\n\n\n\n<pre id=\"block-6a3b6188-5fe7-4787-8dd4-fed93f23d0a6\" class=\"wp-block-code\"><code>  $PathToPython= '\/usr\/bin\/python3';     \/\/Change this if needed to the path of your Python executable \n\n    $PathToScript = $_SERVER&#91;'DOCUMENT_ROOT'];      \/\/Will give: \"\/var\/www\/vhosts\/photonstreams.com\/httpdocs\"\n    $PathToScript .= \"\/myfolder\/myscript.py\";\n\n  \/\/Execute the Python script and capture the output \n  $Output = &#91;]; \n  $Status = 0; \n  exec(\"$PathToPython$PathToScript\", $Output, $Status); \n  if ($Status === 0)\n  {\n    \/\/----- SUCCESS -----\n    echo \"Output from Python script:&lt;br>\";\n    foreach ($Output as $line)\n    {\n      echo htmlspecialchars($line) . \"&lt;br>\";\n    }\n  }\n  else\n  {\n    \/\/----- AN ERROR OCCURED -----\n    echo \"Error executing Python script ($Status).\";\n  }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Running a Python script<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[],"class_list":["post-4738","post","type-post","status-publish","format-standard","hentry","category-files"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4738","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=4738"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4738\/revisions"}],"predecessor-version":[{"id":4742,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4738\/revisions\/4742"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=4738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=4738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=4738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}