Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catch & test script type

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I would like to run some scripts and test their type.

I've tried something like
set run_script "nawk -f $temp" (where $temp is the script name)
if [catch {open "|$run_script|& cat"} input] {
# it's an awk script
}
else
{
set run_script $temp # it's a Cshscript
...
}

Is it the best way to do this and how can I see any error messages and output generated by the script

Another question: How can I test that someone has Tcl/Tk installed?

Cheers,

Fabien
 
fabien,
isn't there a better test than an exec of the scripts?
Are they standard?
do the csh scripts have the #!/bin/csh notation first line?

Basic Idea:
proc check_type {pat} {
foreach N [glob $pat*] {
set xx [open [file join $N] r]
while {[gets $xx line] > 0} {
if {[regexp "#!\/.*" $line]} {
puts "$N is a csh script."
write_log "cshells:$N"
close $xx ; continue
} else {
puts "$N is non-standard."
write_log "awkscripts:$N"
close $xx ; continue
}
}
}
Where write_log is a function that creates a textfile db for you.

You don't even need tcl for this, a shell script using grep would be just as effective.
 
Thanks Jerkie, checking the first line is a good idea!

Now how can I catch any errors or simply display the output of the run in a text window without creating a temp file?

Fab
 
If you are talking tk stuff maybe avia or one of the others
can help you, i don't deal with tk too much.
In any case you could use a list or an array to track your
results and:
parray arrayname
or:
foreach n [lsort listname] {
puts "$n is a shell(or awk) script."
}

Good Luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top