2009-08-24 76 views
0

我试图从PHP执行TCL脚本。我正在使用PHP的proc_open进行通信。但我无法从tcl脚本中获得结果。 有人可以通过代码,让我知道我要去哪里错了吗?在PHP中使用proc_open函数

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 ] " 
+0

你在错误管道上看到了什么? – 2009-08-24 17:54:20

+0

“tclsh”不是Tcl命令。你的意思是“source test.tcl”吗? – 2009-08-24 17:54:53

+0

我没有看到任何错误。我只是在浏览器上看到一个空白页面。 tclsh是一个命令,它用来执行一个tcl文件。 – Vidya 2009-08-25 00:56:58

回答

1

你不换行传递给应用程序(fwrite($pipes[0], "source sum.tcl\n")),这可能是原因?否则,请确保检查函数调用的所有返回值。例如,如果第一个fwrite()失败,则应该提前失败。

+0

我得到了这一个。感谢所有的帮助。 – Vidya 2009-08-25 06:10:21

+2

请在此发布您的答案。 – 2009-08-25 13:28:43