Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script on windows that needs to launch a TCL wish console and source a tcl file (e.g. "source file.tcl") from the console window. Does anyone know of an easy way to accomplish this using Perl?

I have tried using a system call to launch the console window and this works but I'm unable to call the "source file.tcl" command after the window has opened.

I might be taking the wrong approach completely so any suggestions would be appreciated.

Thanks

Replies are listed 'Best First'.
Re: Exec TCL script from Perl?
by Joost (Canon) on Dec 08, 2008 at 23:22 UTC
Re: Exec TCL script from Perl?
by Anonymous Monk on Dec 08, 2008 at 14:55 UTC
      Unfortunately I need to call a tcl script first to setup my TCL environment. I found this script online but it doesn't seem to create the process so I can enter my STDIN
      use strict; use warnings; use Sockets; $wishbin = 'C:\Progra~1\TclScripts\bin\wish84.exe C:\Progra~1\bin\ +WishSetup.tcl'; die "socketpair unsuccessful: $!!\n" unless socketpair(W0,WISH84,1 +,1,0); if ($pid=fork) { print "PID: $pid\n"; select(WISH84); $| = 1; select(STDOUT); print WISH84 'source TCL_Script.tcl',"\n"; # Here is the main loop which receives and sends commands # to wish. while (<WISH84>) { chop; print "Wish sais: <$_>\n"; if (/^quit/) { print WISH84 "destroy .\n"; last; } } wait; } elsif (defined $pid) { open(STDOUT, ">&W0"); open(STDIN, ">&W0"); close(W0); select(STDOUT); $| = 1; exec "$wishbin --"; } else { die "fork error: $!\n"; }
        fork/exec would be a good model to follow on *NIX, but on Windows fork creates a new thread, not a new process.

        I guess TCL is incompatible with Perl, but, depending on the complexity, it might be easy to read the TCL and figure out environment settings in Perl before launching the main TCL script as a child process (using system).
        Or you could rewrite the setup script to use Perl then call it using do.
        Failing that, why can't the main TCL script read the TCL environment file setup?