Query prolog with PHP

840 Views Asked by At

I am trying to make a sudoku game with PHP and prolog, the idea is to use prolog program to solve the sudoku then get the results via PHP, I have write this code down but I'm getting a empty output I have even try to use var_dump to test and i'm getting string '' (length=0) here is my code:

<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Soduku</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="content">
<?php

$output=exec("\"c:/Program Files (x86)/swipl/bin/swipl-win.exe\" -g \"test,halt\" -t \"halt(1)\" test.pl ");
var_dump($output);
echo $output;
echo"<pre>";
print_r($output);
echo"</pre>";

?>


</div>
</body>
</html>

my code after edition

<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Soduku</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="content">
<?php

exec('"c:\\Program Files (x86)\\swipl\\bin\\swipl-win.exe" -g "st,halt" -t "halt(1)"  -s test.pl',$output,$return_var);
var_dump($output);
echo $return_var;


?>


</div>
</body>
</html>

it display this result

array (size=0)
  empty
0
2

There are 2 best solutions below

10
On

The doc says that exec returns the last line and you probably have an empty line as a last line. To get the full output, use the second parameter like this:

exec("\"c:/Program Files (x86)/swipl/bin/swipl-win.exe\" -g \"test,halt\" -t \"halt(1)\" test.pl ", $output);
var_dump($output);
0
On

i have finnaly find out how to do it and it was too simple, i just had to excute swipl.exe instead swipl-win.exe, the right syntax is

$cmd='"c:/Program Files (x86)/swipl/bin/swipl.exe" -g solve_problems,halt -t halt(1) sud.pl' ;