dev vaibhav dev vaibhav - 1 year ago 63
Linux Question

Can't run same tcl code through tcl script?

I can run the same code by going to

from my Konsole but when i try to run it using a tcl script, it gives no output.

I have a file named
which contains this

my name is dev
my name is vaibhav

When i run the command through
, 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
, 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

Any help would be appreciable.



Answer Source

When you use interactive tclsh, the result from the exec command will be returned.

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download