1

My project requires where i need to generate a front end (php) which has all the data input fiels. And using those data as input, I need to execute a TCL script. Once the execution is done, the php page should be able to get the output of the TCL script and show it.

I have generated a sample script but not able to execute it. can you guys please help me.

Thanks in advance

My php script is:

<!DOCTYPE html>
<html>
    <body>
        <?php
            function print_procedure ($arg) {
                echo exec("/usr/bin/tclsh /test.tcl");
            }
            $script_name='test.tcl';
            print_procedure($script_name);
        ?>
    </body>
</html>

My TCL script is:

set a 10
set b 20
set c [expr $a + $b]
return c
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
Harsh
  • 13
  • 5

1 Answers1

1

Your tcl script should write on stdout:

set a 10
set b 20
set c [expr {$a + $b}]
puts $c

If your tcl script is supposed to output multiple lines:

e.g.:

puts $c
puts $c
puts $c

you can capture them in a PHP array:

e.g.:

$array = array();
function print_procedure ($arg) {
    echo exec("/opt/tcl8.5/bin/tclsh test.tcl",$array);
    //print_r($array);
}
Javide
  • 2,477
  • 5
  • 45
  • 61
  • Thank you for helping me out. It worked and I was able to get the output onto the front end. – Harsh Jul 10 '13 at 10:32