在PHP中使用proc_open函数

在PHP中使用proc_open函数,php,tcl,Php,Tcl,我正在尝试从PHP执行一个TCL脚本。我使用PHP的proc_open进行通信,但是我无法从tcl脚本获得结果。 有人能检查一下代码,告诉我哪里出了问题吗 PHP代码 <?php $app = 'tclsh84.exe'; $spec = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w")); $process = proc_open($app, $spec, $pipes); if (is_resourc

我正在尝试从PHP执行一个TCL脚本。我使用PHP的proc_open进行通信,但是我无法从tcl脚本获得结果。 有人能检查一下代码,告诉我哪里出了问题吗

PHP代码

<?php
$app = 'tclsh84.exe';

$spec = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w"));

$process = proc_open($app, $spec, $pipes);

if (is_resource($process)) 
{

    fwrite($pipes[0], 'source sum.tcl ');
    fwrite($pipes[0], 'tclsh test.tcl ');
    fclose($pipes[0]);

  echo stream_get_contents($pipes[1]);
  fclose($pipes[1]);

 //   echo fread($pipes[1],1024).'<hr>';


   proc_close($process);
}
?>


//sum.tcl 
proc sum {arg1 arg2} {
    set x [expr {$arg1 + $arg2}];
    return $x
}

//test.tcl
puts " the sum is [sum 10 9 ] "

//sum.tcl
过程和{arg1 arg2}{
集合x[expr{$arg1+$arg2}];
返回$x
}
//test.tcl
将“总和为[总和10 9]”

您没有向应用程序传递换行符(
fwrite($pipes[0],“source sum.tcl\n”)
),这可能是原因吗?否则,请确保检查函数调用的所有返回值。例如,如果第一个fwrite()失败,您应该尽早失败。

您在错误管道上看到了什么?“tclsh”不是Tcl命令。你是说“sourcetest.tcl”吗?我没有看到任何错误。我只是在浏览器上看到一个空白页。tclsh是一个命令,用于执行tcl文件。我知道tclsh是一个命令。但它不是tclsh84.exe能够理解的命令(这是$process的$app)。另外,proc_close的退出状态是什么?您可以从$pipes[2]读取哪些错误消息?您需要自己进行大量调试。tclsh正在创建一个新的子进程。因此脚本没有执行。我只是从我得到的同一个文件中获取了该文件并调用了proc。谢谢你的帮助。请把你的答案贴在这里。