Executing tcl script inside php

863 views Asked by At

I am trying to execute tcl script inside php using passthru function. TCL script perfectly executes on the normal unix terminal. Whereas in php its not giving expected results on the browser.

I am passing the environment variable using passthru function in php. The environment variable is getting passed correctly but I am noticing the rest of the commands are not giving out the result. So I experimented trying to execute ls command and date command.

date command gives the output on the browser whereas ls doesn't give any output on the browser.

Why is this happening? It's the same result with who and other commands with large output. Is there anything I am missing here??

Here is my sample tcl script ls_sample.tcl

puts "entering tcl"
set date_variable [exec date]
puts $date_variable
set ls_variable [exec ls]
puts $ls_variable 

Sample output on the browser:

executing tclscript entering tcl Thu Oct 18 23:23:38 PDT 2012 

why is ls not printed? Whereas it works completely fine on the unix terminal?

1

There are 1 answers

1
Marco Pallante On

I think it could be an Apache/Php/your system configuration problem. I just tried the same example under my machine and got the right result:

entering tcl Sat Oct 27 11:08:03 CEST 2012 blog forum index.rvt launchtcl.php pttest.tcl sd test.tcl test2.tcl

I also tried to reproduce the problem by doing these things, but it always worked for me:

  • ls /usr/bin, for getting a longer string
  • who, for variety
  • chowned the .tcl file to a different user/group from the one used by Apache (www-data:www-data)
  • chowned the .tcl file (as before), and chmod o-rx the directory
  • switched from passthru('tclsh pttest.tcl') to passthru('./pttest.tcl'), made pttest.tcl executable and added #!/usr/bin/tclsh as first line
  • the same as before, but chowning the pttest.tcl file

None of these tests gave me your problem. I'm now adding the Apache configuration for the testing directory I used.

<Directory />
    Options -Indexes FollowSymLinks MultiViews
    DirectoryIndex index.html index.htm index.tcl index.rvt
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Sorry if I can't answer your question, but maybe these information can help you.