1

I have a Shell script that reads in another file as an argument. In Shell terminal, I use it like the following:

source checker.sh waiver.file

Now, I would like to source this shell script in a TCL script like following
TCL_script.tcl

link
set RUN .
exec checker.sh waiver.file

When I execute the above TCL script, the terminal is just hung and it doesn't work.

Can any experts here please help me in running a Shell script in a TCL script?

Thanks!

4
  • 1
    What happens when you run the script manually via: ./checker.sh waiver.file? Commented Aug 12, 2020 at 22:02
  • Make sure it has execute permissions. What. are link and RUN for? Commented Aug 13, 2020 at 3:34
  • 1
    Does checker.sh exist in your path? Commented Aug 13, 2020 at 4:21
  • @Shawn Yes, checker.sh does exist in the path. Commented Aug 13, 2020 at 22:50

1 Answer 1

5

How to run that depends critically on how exactly that checker.sh works. The issue is that the shell's source command works by reading the script and executing it within the current shell session (Tcl's source works similarly, but it's for a different language). Because it is in the same session, it has all sorts of access to capabilities that it effectively would not as a subprocess (or rather it would have them, but they wouldn't persist).

The simple way to run that from Tcl is this (assuming you're in the right directory):

exec sh checker.sh waiver.file

I would not be surprised if that has problems! Unfortunately, the set of possible problems is so thoroughly wide that it's extremely hard to guess how to resolve them ahead of time.

That said, the fact that you're getting a hang is useful information. That probably means that the script is trying to access standard in and out in ways that are not particularly happy with a pipeline. We can try resolving that with redirections:

exec sh checker.sh waiver.file <@stdin >@stdout 2>@stderr

If that doesn't work, you might need to run things using Expect. The expect program is Tcl, but with some extra commands. This might be enough to get you started:

spawn sh
send "source checker.sh waiver.file\r"
interact

There's an awful lot more to using Expect well.

(It's possible that rewriting checker.sh might be easier; the details matter utterly here.)

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

Comments

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.