简体   繁体   中英

How to execute tcl script from php page and retrive the output back

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

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:

eg:

puts $c
puts $c
puts $c

you can capture them in a PHP array:

eg:

$array = array();
function print_procedure ($arg) {
    echo exec("/opt/tcl8.5/bin/tclsh test.tcl",$array);
    //print_r($array);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM