0

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 ] "
6
  • What do you see on the error pipe? Commented Aug 24, 2009 at 17:54
  • "tclsh" is not a Tcl command. Did you mean "source test.tcl"? Commented Aug 24, 2009 at 17:54
  • I don't see any error . I just get a blank page on the browser. tclsh is a command , it is used to execute a tcl file. Commented Aug 25, 2009 at 0:56
  • I know tclsh is a command. But it is not a command that tclsh84.exe understands (which is the $app of your $process). Also, what's the exit status from proc_close? What error messages can you read from $pipes[2]? You have a lot of debugging you should be doing yourself. Commented Aug 25, 2009 at 13:26
  • tclsh was creating a new child process .hence the script was not executing .I just sourced the file and called the proc from the same file Commented Aug 25, 2009 at 13:39

1 Answer 1

1

You're not passing newlines to the application (fwrite($pipes[0], "source sum.tcl\n")), 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.

Sign up to request clarification or add additional context in comments.

2 Comments

I got this one. Thanks for all the help.
Please post your answer here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.