1

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>
2
  • what is the output ? and what error do you encounter ? Commented Apr 26, 2015 at 12:23
  • its showing only the header " hey there!" on browser . $return value is not displayed on browser Commented Apr 27, 2015 at 4:37

2 Answers 2

2
<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>
Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

i'm using xampp on windows.. thats why 3rd step is not working for me.... .can you elaborate 2nd point.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.