smasher
smasher

Reputation: 294

how to run python script from php on xamp?

Following is the php code that I was using. I am trying to run this script(residing in the same directory as the php file is in) and want to display the output of the script on webpage. Script is working fine through command prompt, but not working thru php script.

<html>
<head>
<title>py script</title>
</head>
<body>
<h1>hey there!</h1>
<?
$pyscript = 'C:\\xampp_new\\htdocs\\projectx\\USR.py';
$python = 'C:\\Python27\\python.exe';
exec("$python $pyscript ", $output, $return );
echo $return;
?>
</body>
</html>

Upvotes: 1

Views: 1406

Answers (2)

HelloWorld
HelloWorld

Reputation: 76

<html>
<head>
<title>py script</title>
</head>
<body>
<h1>hey there!</h1>
<?
$pyscript = 'C:/xampp_new/htdocs/projectx/USR.py';
$python = 'C:/Python27/python.exe';
$command=escapeshellcmd('C:/xampp_new/htdocs/projects/USR.py');
$output=shell_exec($command);
echo $output;
?>
</body>
</html>

Upvotes: 2

Uri Goren
Uri Goren

Reputation: 13690

There are several options why your exec call won't work:

  1. Are you running om safe_mode ? exec is disabled in safe mode
  2. Your std output is at $output which is more interesting than the return value
  3. if your python script working ? try in PHP: exec("$python $pyscript >test.txt"); and see if your text file has anything in it

Upvotes: 0

Related Questions