I can run the same code by going to tclshfrom my Konsole but when i try to run it using a tcl script, it gives no output.
I have a file named name which contains this
my name is dev
my name is vaibhav
When i run the command through tclsh , it gives the required output.
Command is exec grep "dev" name and Output is my name is dev
But when i run it through tcl script named call.tcl, it gives no output! Its contents are :-
#! /usr/bin/tclsh exec grep "dev" name
I have verified the address of tclsh in the first line and the file is present there. I am using redhat-release-5Client-5.5.0.2
Any help would be appreciable.
Thanks
Dev
Advertisement
Answer
When you use interactive tclsh, the result from the exec command will be returned and by default they will be printed in the console.
But, when you run at as a standalone script, it won’t be printed to console (stdout) unless you manually use the puts command to print the same.
puts [exec grep "dev" name]
Also, you can save it to a variable using set command
set result [exec grep "dev" name] puts $result