0

The below command works fine when i run it from unix box, but when I execute it from a tcl script its not working. please help me how to execute the command.

java -jar diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml

I have tried the following lines of code

exec "java -jar diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml"

eval "java -jar diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml"
2
  • 1
    Please add the error that you get the next time too. Commented Aug 8, 2013 at 20:58
  • Actually, it works fine when you run it from a UNIX shell. The shell splits the string into words. If you for some reason need the services of a shell for starting java, use e.g. exec sh -c "java -jar diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml", otherwise see Johannes answer. Commented Aug 8, 2013 at 23:09

2 Answers 2

5

Use separate arguments.

exec java -jar diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml

I'm not sure if exec looks in the path, so it is better do do the following:

exec {*}[auto_execok java] diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml

Or if you are on 8.4 (which is end of life by the way)

eval [linsert {exec diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml} 1 [auto_execok java]]
Sign up to request clarification or add additional context in comments.

1 Comment

FYI, exec most certainly does use the path.
1

There are three ways to do it:

exec java -jar diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml

No quotes; each Tcl word becomes a separate argument.

set command "java -jar diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml"
exec {*}$command
# or in 8.4 and before, one of these:
# eval exec $command
# eval [list exec] [lrange $command 0 end]
# eval [linsert $command 0 exec]

Or, if you prefer shell syntax to Tcl syntax:

set command "java -jar diffkit-0.9.0/diffkit-app.jar -planfiles plan.xml"
exec /bin/sh -c $command

This last one is very useful when you need to do complex redirections; they're currently easier to do in the Bourne shell (and its derivatives) than in Tcl. It (probably) won't work on Windows though; the equivalent with firing stuff through CMD.EXE is unfortunately a bit horrible.

1 Comment

Usually, when you use windows, use cmd.exe /c ... or even cmd.exe /c start {} ...

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.