f



Why can execution results in tcl shell differ than if using tcl script??

Hi,

I have been posting a thread here:
http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/983d7ef3e4b1ab54#

I have another question that might be related to it, I'm doing set of
tcl commands (involving external shell commands execution) one time in
tcl shell, and the other from a tcl script..

Although both command sequences are the same, I get quite different
results!!! Why did this happens??

Thanks,
Ahmad
0
7/30/2009 9:51:32 PM
comp.lang.tcl 23428 articles. 2 followers. Post Follow

5 Replies
1867 Views

Similar Articles

[PageSpeed] 17

Ahmad wrote:
> Hi,
> 
> I have been posting a thread here:
> http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/983d7ef3e4b1ab54#
> 
> I have another question that might be related to it, I'm doing set of
> tcl commands (involving external shell commands execution) one time in
> tcl shell, and the other from a tcl script..
> 
> Although both command sequences are the same, I get quite different
> results!!! Why did this happens??
> 
> Thanks,
> Ahmad

The interactive Tcl shell has access to external functionality that a 
running script doesn't.  That's done to make the interactive environment 
easier to work with.  What, specifically, is the command sequence you're 
issuing in both cases?

Jeff
0
jeff_godfrey (836)
7/30/2009 10:25:40 PM
Hi Jeff,

Thank you for your reply.

I've a tcl script that finally creates a certain script, that is when
I run from shell using "calibredrv -gui <certainRunScript>" 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..

I think i'm misusing catch/exec and that's what made the problem??

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

On Jul 31, 1:25=A0am, Jeff Godfrey <jeff_godf...@pobox.com> wrote:
> Ahmad wrote:
> > Hi,
>
> > I have been posting a thread here:
> >http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/983...
>
> > I have another question that might be related to it, I'm doing set of
> > tcl commands (involving external shell commands execution) one time in
> > tcl shell, and the other from a tcl script..
>
> > Although both command sequences are the same, I get quite different
> > results!!! Why did this happens??
>
> > Thanks,
> > Ahmad
>
> The interactive Tcl shell has access to external functionality that a
> running script doesn't. =A0That's done to make the interactive environmen=
t
> easier to work with. =A0What, specifically, is the command sequence you'r=
e
> issuing in both cases?
>
> Jeff

0
7/30/2009 10:40:07 PM
Ahmad wrote:
> Hi Jeff,
> 
> Thank you for your reply.
> 
> I've a tcl script that finally creates a certain script, that is when
> I run from shell using "calibredrv -gui <certainRunScript>" 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):

Ahmad,

I'm far from an expert in the art of [exec], but here are a few tips...

- First, I'd remove the "catch" command from around your exec call. 
That's likely masking the real problem.  Once it's gone, I'd bet you'll 
get an error that'll lead you in the right direction.

- What is calibredrv, and probably more importantly, *where* is 
calibredrv?  Interactively, I think it'll be found if its anywhere in 
the PATH, but that's not the case when run as a script.  If it's not in 
the local folder, you need to specify a path with it.

Jeff
0
jeff_godfrey (836)
7/30/2009 11:10:07 PM
Jeff Godfrey wrote:
> Interactively, I think it'll be found if its anywhere in 
> the PATH, but that's not the case when run as a script.
> 
> Jeff

I was informed via private email that the above is incorrect.  And, 
after RTFM, I've verified that to be the case.  [exec] does indeed 
search the directories defined in PATH, whether interactive or not 
(assuming the command name doesn't contain slashes)...

Sorry for the misinformation.

Still, I think removing your [catch] will be enlightening...

Jeff
0
jeff_godfrey (836)
7/31/2009 1:42:46 AM
At Thu, 30 Jul 2009 20:42:46 -0500 Jeff Godfrey <jeff_godfrey@pobox.com> wrote:

> 
> Jeff Godfrey wrote:
> > Interactively, I think it'll be found if its anywhere in 
> > the PATH, but that's not the case when run as a script.
> > 
> > Jeff
> 
> I was informed via private email that the above is incorrect.  And, 
> after RTFM, I've verified that to be the case.  [exec] does indeed 
> search the directories defined in PATH, whether interactive or not 
> (assuming the command name doesn't contain slashes)...
> 
> Sorry for the misinformation.

It is possible that the value of PATH might be different under different
conditions (interactive vs script). There is much that the original
poster has not told us (the NG).

> 
> Still, I think removing your [catch] will be enlightening...

Yes indeed...

> 
> Jeff
>                                  

-- 
Robert Heller             -- 978-544-6933
Deepwoods Software        -- Download the Model Railroad System
http://www.deepsoft.com/  -- Binaries for Linux and MS-Windows
heller@deepsoft.com       -- http://www.deepsoft.com/ModelRailroadSystem/
  
0
heller (3031)
7/31/2009 11:45:44 AM
Reply: