when I worked with wamp, I had no problems, because I could have all of my files in same directory, but now I am using hosts server, so I have to change the path to the file I am working with, so PY files would work. Hello.php
is in /public_html/wp-content/plugins
and PY, that php is working with, is in /public_html/cgi-bin
. This is hello.php code:
<?php # -*- coding: utf-8 -*-
/* Plugin Name: hello */
header('Content-Type: text/html; charset=cp1252');
add_shortcode( 'hello', 'execute_python_with_argv' );
function execute_python_with_argv(){
ob_start();
$description = array (
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
);
$application_system = "python ";
$application_path .= plugin_dir_path( __FILE__ );
$application_name .= "hello.py";
$separator = " ";
$application = $application_system.$application_path.$application_name.$separator;
$pipes = array();
$proc = proc_open ( $application , $description , $pipes );
if (is_resource ( $proc ))
{
echo stream_get_contents ($pipes [1] ); //Reading stdout buffer
}
echo "soup";
$output = ob_get_clean();
return $output;
}
I have tried changing $application_path .= plugin_dir_path( __FILE__ );
to $application_path = $_SERVER['DOCUMENT_ROOT']; $application_path .= "/public_html/cgi-bin/hello.py";
didn't do anything. Any help would be appreciated, thanks for reading.