如何从php页面执行tcl脚本并检索输出



我的项目需要在哪里生成一个拥有所有数据输入字段的前端(php)。使用这些数据作为输入,我需要执行一个TCL脚本。一旦执行完成,php页面应该能够获得TCL脚本的输出并显示出来

我已经生成了一个示例脚本,但无法执行它。你们能帮帮我吗。

提前感谢

我的php脚本是:

<!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>

我的TCL脚本是:

set a 10
set b 20
set c [expr $a + $b]
return c

您的tcl脚本应该在stdout:上编写

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

如果您的tcl脚本应该输出多行:

例如:

puts $c
puts $c
puts $c

您可以在PHP数组中捕获它们:

例如:

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

最新更新