This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Help for those learning Tcl or writing their own scripts.
BCyo+8C4
Voice
Posts: 24 Joined: Sun Sep 03, 2006 11:11 am
Post
by BCyo+8C4 » Sun Sep 03, 2006 11:20 am
Hi,
I'd like to call awk from a tcl script, but for some reason it doesn't work. No error message returned.
In my tcl I have this line to call the script:
Code: Select all
exec awk -f alfa.awk -v was='{tr}{td}$mask' bans-$chan.txt > bans-$chan-tmp.txt
All parameters are send to the script correctly and the awk command works fine like this when called from bash.
Changing the script to point to an invalid .awk file makes it throw an error, so it seems awk is actually run. It just doesn't do what it's supposed to do when called from tcl.
Anyone got an idea what I got wrong?
demond
Revered One
Posts: 3073 Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:
Post
by demond » Mon Sep 04, 2006 12:13 am
escape curly braces with backslashes
connection, sharing, dcc problems? click
<here>
before asking for scripting help, read
<this>
use
BCyo+8C4
Voice
Posts: 24 Joined: Sun Sep 03, 2006 11:11 am
Post
by BCyo+8C4 » Mon Sep 04, 2006 6:33 am
the problem is not the brackets, even this test code doesn't work when called from tcl:
Code: Select all
exec awk -f alfa.awk -v was='test' bans-#test.txt > bans-#test-tmp.txt
demond
Revered One
Posts: 3073 Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:
Post
by demond » Mon Sep 04, 2006 12:42 pm
my guess is that space between the redirection character and output file name is not being interpreted as in shell
try without it, i.e. >bans-$chan-tmp.txt
connection, sharing, dcc problems? click
<here>
before asking for scripting help, read
<this>
use
rosc2112
Revered One
Posts: 1454 Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania
Post
by rosc2112 » Mon Sep 04, 2006 2:24 pm
Tcl Built-In Commands - exec manual page
If an arg (or pair of args) has one of the forms described below then it is used by exec to control the flow of input and output among the subbprocess(es). Such arguments will not be passed to the subprocess(es). In forms such as ``< fileName'' fileName may either be in a separate argument from ``<'' or in the same argument with no intervening space (i.e. ``<fileName'').
> fileName
Standard output from the last command is redirected to the file named fileName, overwriting its previous contents.
rosc2112
Revered One
Posts: 1454 Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania
Post
by rosc2112 » Mon Sep 04, 2006 2:26 pm
BCyo+8C4 wrote: the problem is not the brackets, even this test code doesn't work when called from tcl:
Code: Select all
exec awk -f alfa.awk -v was='test' bans-#test.txt > bans-#test-tmp.txt
Just curious, what does your awk script try to accomplish and why could it not be done in native tcl code?
BCyo+8C4
Voice
Posts: 24 Joined: Sun Sep 03, 2006 11:11 am
Post
by BCyo+8C4 » Tue Sep 05, 2006 10:21 am
got it. it was the ' chars + the space after >
working code:
Code: Select all
exec awk -f alfa.awk -v was={tr}{td}$mask bans-$chan.txt >bans-$chan-tmp.txt
exec mv bans-$chan-tmp.txt bans-$chan.txt