0

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 ] "
4

1 に答える 1

1

アプリケーションに改行を渡していません ( fwrite($pipes[0], "source sum.tcl\n"))。それが原因でしょうか? それ以外の場合は、関数呼び出しのすべての戻り値を確認してください。たとえば、最初の fwrite() が失敗した場合は、早期に失敗する必要があります。

于 2009-08-24T14:09:54.370 に答える