1

I have a file with 4 perl commands , I want to open the file from the tcl and execute each perl command.

TCL script

runcmds $file

proc runcmds {file} {

    set fileid [open $file "r"]
    set options [read $fileid]
    close $fileid

    set options [split $options "\n"]    #saperating each commad  with new line

    foreach line $options {
    exec perl $line  
    }
}

when executing the above script I am getting the error as "can't open the perl script /../../ : No Such file or directory " Use -S to search $PATH for it.

1
  • Overall, it looks good to me. If I were you I would try with full paths for everything: both the perl binary, as well as anything that may come in the $options variable. Commented Jan 14, 2014 at 3:59

1 Answer 1

2

tl;dr: You were missing -e, causing your script to be interpreted as a filename.


To run a perl command from inside Tcl:

proc perl {script args} {
    exec perl -e $script {*}$args
    # or in 8.4: eval [list perl -e $script] $args
}

Then you can do:

puts [perl {
    print "Hello "
    print "World\n"
}]

That's right, an arbitrary perl script inside Tcl. You can even pass in other arguments as necessary; access from perl via @ARGV. (You'll need to add other options like -p explicitly.)

Note that this can pass whole scripts; you don't need to split them up (and probably shouldn't; you can do lots with one-liners but they tend to be awful to maintain and there's no technical reason to require it).

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

1 Comment

Hi Donal thaks for the info, Can you give some more info , how to write if the $line is a perl file

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.