tags:

views:

273

answers:

2

Hello All,

I need to execute a TCL script from PHP. At the moment I am using the following code

<?php 
echo passthru("tclsh83 Testcases/source.tcl ");
?>

This is working. But this creates a shell for each call . How do I open a shell and communicate to and fro from the TCL script . Any pointers will be appreciated .

Regards, Mithun

A: 

I got to know the way to pass values from php script to TCL script passthru("tclsh83 Testcases/source.tcl $arg1 $arg2 "); // command line arguments Is there a better way to execute the TCL script ? Thanks , Mithun

So what's wrong about this way? It is the best way if you will always be passing only 2 parameters and they will be from a trusted source. If not, you can have an array of parameters, escape them using escapeshellarg(), join() them and put the result into the command string. For example:

$params = array( /* <...> */ );
echo passthru('tclsh83 Testcases/source.tcl ' .
              join(' ', array_map('escapeshellarg', $params)));
Ignas R
A: 

If you have lots of data to send to the tcl script, you could open read and write pipes with proc_open(). Then, in the tcl script, use gets stdin varname to read a line from stdin.

glenn jackman