Jump to content

[Answered] Running Python from Php - Alternative for shell_exec()?


rodbm

Recommended Posts

Hey there everyone,

 

I have good knowledge of python but I'm still learning Php (well to be honest I started learning it for this purpose).

I have a Python script in /cgi-bin and it works fine when I go to mydomain.heliohost.org/cgi-bin/script.py. What I want to do is make it so that it starts from a Php file outside of /cgi-bin.

 

I tried shell_exec() but I'm getting the "Warning: shell_exec() has been disabled for security reasons..." message. I know this function can be used for malicious purposes and that's why it's blocked.

I tried some other functions but nothing seems to work or I'm doing it wrong.

 

Question: Can this be done without the use of shell_exec() by any chance?

 

I know there are some duplicate topics of this subject, but as I said I tried a few solutions posted on them and these didn't work.

 

Thanks for your attention!

Link to comment
Share on other sites

Assuming the python can be run in a browser by calling it’s URL and it producing browser-compatible output (I.e. http headers, etc.), call it via file_get_contents() using its full public URL. The function will call the script and return the output for further use.

Link to comment
Share on other sites

Thank you wolstech.
 
I tried that before and I still can't get this function to work. The py file I'm using is as follows:

 

#!/usr/bin/python
 
print("Content-Type: text/html\n\n")
 
print("Heliohost rules!")

 

 

And the php I'm trying to make it to work is as follows:

<?php
$grab = file_get_contents("http://mydomain.heliohost.org/cgi-bin/test.py");
echo $grab;
?>

 

I get the message:

Warning: file_get_contents(http://mydomain.heliohost.org/cgi-bin/test.py): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in ../test.php on line 3

 

I with the dir path instead of the url but it just returns the full code in plain text.

Am I doing something wrong?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...