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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems generating a command

Status
Not open for further replies.

marcyboy

Programmer
Nov 19, 2008
3
GB
Hi just trying to get to grips with tcl.

I am having to use the Oracle version and it is difficult to understand what version I am using. (using the OMB extension set)

However, I am trying to open a file for reading by passing in the file name as a argument from the tcl script.

this all works OK

but when I try to open the file

set file_id [open $my_file_fqn w]

it fails I then tried to eval by

cmd [list "set file_id [open " $my_file_fqn w]]

eval $cmd

even when I separate it out it seems to put curley braces around the [


Any thoughts on this?

Is there a much easier way? Someone must have had to do this at sometime

many thanks
 
What if you use the file name directly? That is, instead of the value of the variable, "my_file_fqn", use the explicit file name. If that works, then somehow the variable is not set properly and I would suspect scope.

_________________
Bob Rashkin
 
Thnks Bong

dynamic file creation

I am making progress

this works:

# escape the [] as the parser still tries to subst the
# internal commands
set cmd1 [subst {\[open $my_big_file w\]}]
# list puts curley braces around so I used concat
#
set cmd2 [concat set file_id $cmd1]
eval $cmd2
puts $file_id "My big words"
close $file_id

but now the $file id seems to take over as stdout when called form UNIX!!

I havn't given up yet

I need to work out what happens to the stdout
 
managed to get this proc to work nicely
If anyone finds it of use.

It's a bit clunky and if anyone has a sleeker version let me know

proc dmic_file {file_fqn file_type} {
set cmd1 [subst {\[open $file_fqn $file_type\]}]
set cmd2 [concat set channel $cmd1]
eval $cmd2
global file_id
set file_id $channel
}

set my_big_file "/tmp/my_big_file.txt"

eval dmic_file $my_big_file w

puts $file_id "my big words"

close $file_id
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top