How can I redirect stdout into a file in tcl

前端 未结 7 1461
不思量自难忘°
不思量自难忘° 2020-12-11 16:36

how can I redirect a proc output into a file in tcl, for example, I have a proc foo, and would like to redirect the foo output into a file bar. But got this result



        
7条回答
  •  心在旅途
    2020-12-11 17:07

    We can try in this way also

    % proc foo {} { return "hello world" }
    
    % foo
    
    hello world
    
    % set fd [open "a.txt" w]
    
    file5
    
    % set val [foo]
    
    hello world
    
    % puts $fd $val
    
    % close $fd
    
    % set data [exec cat a.txt]
    
    hello world
    

提交回复
热议问题