I've a tcl script that finally creates a certain script, that is when
I run from shell using "calibredrv -gui <thisOutputScript>" from
command line it do exactly what I expect.
I have tried two scenarios of trials, and only one of them works:
1. Open tclsh --> Run the following TCL line from tclsh interpreter
(where the variable runScript is probably defined)
catch {exec -- calibredrv -gui $runScript >/dev/null 2>/dev/null}
msg
2. From inside my tcl script, the same line (copy and paste):
catch {exec -- calibredrv -gui $runScript >/dev/null 2>/dev/null}
msg
Results:
Scenario #1 works perfectly, and $msg is alway empty (using puts)
Scenario #2 doesn't work, where CalibreDRV window opens and
immediately get closed, and also $msg is empty!!!
I need the command "calibredrv -gui $runScript" process to be waited
until finished, then in tcl check if a certain file that it should
generate exists or not (i.e. wait for this process) so I didn't
execute it in background..
Why does it fail in the tcl script??
In general, how to wait for a shell command while being executed
within tcl?
Any ideas?
Thanks,
Ahmad
--
+------------------------------------------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
> 2. From inside my tcl script, the same line (copy and paste):
> catch {exec -- calibredrv -gui $runScript >/dev/null 2>/dev/null} msg
How exactly do you start the tcl-script in #2 ?
Perhaps, calibredrv behaves differently whether it has a tty as stdin
or not, and maybe your tcl-script gets started with no tty, whereas the
interactive tclsh (most likely) does have one.
Is there a similar difference when you start any of these from unix-shell (bash)
calibredrv -gui script.tcl >/dev/null 2>/dev/null
or
calibredrv -gui script.tcl >/dev/null 2>/dev/null </dev/null
>
> Why does it fail in the tcl script??
>
The best way to know why it is failing is to use this notation
instead:
set rc [catch {exec -- calibredrv -gui $runScript} msg]
puts "return code from catch is $rc"
puts "msg is $msg"
I've tried all of the above, I've tried to removed "catch" and I got a
meaningless error.. Which is:
"Cannot find file ..... no such file or directory." and gives my
script absolute path file name but it's clipped at the end. (e.g. if
its /foo/bar/script.tcl => it says: Cannot find file "/foo/bar/sc" no
such file or directory.
I can get calibredrv working from the tcl scrip using:
set procId [eval {calibredrv -gui ..... >/dev/null 2> /dev/null &}]
It only works if it's with the '&' (in background), I want that the
script waits until calibredrv stops execution to further process
another command on its results. the '&' sign prevent this!
Any idea?
Thanks,
Ahmad
Well, I think it's a mistake to consider such an error meaningless - you
need to find the source of that error. Are you *sure* there's nothing
strange just after the "bar/sc" in your script invocation. Otherwise, I
don't know why the message would be clipped...
How are you invoking this script?
Jeff
Try this:
puts "runscript is '$runscript'"
set rc [catch {exec -- calibredrv -gui $runScript} msg]
puts "return code from catch is $rc"
puts "msg is $msg"
Does the runscript variable contain what you expect?
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
I've tried all of the above, I've tried to removed "catch" and I got a
meaningless error.. Which is:
"Cannot find file ..... no such file or directory." and gives my
script absolute path file name but it's clipped at the end. (e.g. if
its /foo/bar/script.tcl => it says: Cannot find file "/foo/bar/sc" no
such file or directory.
I can get calibredrv working from the tcl scrip using:
set procId [eval {calibredrv -gui ..... >/dev/null 2> /dev/null &}]
It only works if it's with the '&' (in background), I want that the
script waits until calibredrv stops execution to further process
another command on its results. the '&' sign prevent this!
Any idea?
Thanks,
Ahmad
On Jul 31, 2:15 pm, "Larry W. Virden" <lvir...@gmail.com> wrote:
> On Jul 30, 5:29 pm, Ahmad <ahmad.abdulgh...@gmail.com> wrote:
>
>
>
> > Why does it fail in the tcl script??
>
Here's what I sometimes do when I am trying to get something like this
to work.
First, make a copy of the code and delete all the code that would
execute after the statement that is causing the problem.
Test the copy. Does it still fail?
If so, start removing statements that seem to be unrelated to the
problem. Make certain you keep the previous version each time.
If you reach a point where the problem goes away, back up one version.
See if there is anything else unrelated that can be removed. If not,
then you have reached the smallest program that exhibits the issue.
Make certain you have tested using the latest release of Tcl and the
extensions. Make certain that the problem isn't one that has already
been fixed.
Look at the remaining code. Is there any way to reduce the program by
replacing a database with setting constant values into a variable? Any
thing else you can do to reduce local dependencies - replace calls to
external programs with calls to tcl procs that return constant values,
etc.?
The goal is to get a small coherent example of code that could be
emailed to someone at another site , and when they run the code, they
see the same problem that you are seeing.
If you can do that, then you have provided the best possible situation
for resolving the problem.
Also, when reporting a problem, be certain to mention:
what version of tcl and other extensions is being used
What operating system (and distribution, etc.) is being used
What hardware is being used
The exact, literal, complete error message that is being produced.
Good luck.
Have you tried to invoke the script with "calibredrv -gui -s
<script>"?
Yijun
Find Calibre DESIGNrev Q&A @ Mentor Graphics Communities
http://communities.mentor.com/mgcx/community/icnanometer/calibre_viewers