2009-08-24 80 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