doulao2128 2009-08-24 13:52
浏览 108
已采纳

在PHP中使用proc_open函数

I am trying to execute a TCL script from PHP. I am using PHP's proc_open for the communication .But I am unable to get the result from the tcl script . Can someone go through the code and let me know where I am going wrong ?

PHP code

<?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 ] "
  • 写回答

1条回答 默认 最新

  • drztpx8735 2009-08-24 14:09
    关注

    You're not passing newlines to the application (fwrite($pipes[0], "source sum.tcl ")), could that be the cause? Otherwise make sure to check all return values of your function calls. You should fail early, if the first fwrite() fails, for example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿