top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to write the CLI console output into a file using TCL script ?

+2 votes
826 views
How to write the CLI console output into a file using TCL script ?
posted Dec 19, 2013 by Nithin Kp

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Can u provide some more detail on CLI i.e. what type of CLI  it is etc etc...
Dont know what you are trying to do, but what I understood is that you are trying to output the stdout to a file for that you can use dup (http://wiki.tcl.tk/1996 ) command.

1 Answer

+1 vote
proc foo {} { puts "hello world" }
proc reopenStdout {file} {
    close stdout
    open $file w        ;# The standard channels are special
}

reopenStdout ./bar
foo
reopenStdout /dev/tty   ;# Default destination on Unix; Win equiv is CON:

Be aware that if you do this, you lose track of where your initial stdout was directed to (unless you use TclX's dup to save a copy).

answer Dec 19, 2013 by Satyabrata Mahapatra
Similar Questions
+2 votes

We develop embedded software for 32-bit micros using Windows as the development platform.

We are seeking a general purpose scripting language to automate certain tasks, like cleaning out certain directories of certain types of files in preparation for ZIP'ing, generating certain source files automatically, etc.

Selection criteria:

a)Should be able to compile the script interpreter as a monolithic executable (no .DLL dependencies, etc.) for easy versioning and distribution of the script interpreter. (Note that I'm not asking that the script be a single executable, just the interpreter. To run a script you'd need both the script and the interpreter. The script would be a text file, and the interpreter would be a single .EXE.)

b)Should be extensible, in that one could add commands or library functions to the script interpreter in C (for efficiency), and the whole script interpreter could again consist of a single executable with no other dependencies. (Note that I'm not asking that the script be a single executable, just the interpreter. To run a script you'd need both the script and the interpreter. The script would be a text file, and the interpreter would be a single .EXE.)

c)Should be able to spawn compilers and capture the output, do file I/O, and all the other minor expected stuff.

d)Graphical capability would be nice.

I know that Tcl/Tk would do all of the above, but what about Python or any other alternatives?

0 votes

I'm trying to write a python script that writes some content to a file root through sudo, but it's not working at all. I am using:

 channel = 'stable'
 config_file = '/opt/ldg/etc/channel.conf'
 command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]
 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 out, _ = p.communicate()

But it seems as if this isn't doing anything.

I just want to write the contents of the variable channel to the file /opt/ldg/etc/channel.conf. But whatever I try just doesn't work. Can anyone offer any pointers?

0 votes

I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file.

Presently I am using this:

with open('index.txt','w') as f:
 f.write("".join(data))
 f.close()

where data is a list of strings which I want to dump into the index.txt file

...