[brlcad-users] MGED Tip: saving command output to a text file
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: Christopher S. M. <mor...@ar...> - 2007-04-06 21:08:37
|
There are some commands in MGED (e.g. the tree command) that have an option to save output to a file, but often you can find yourself in a situation where you are using commands and you would to save output to a file yet the command you're using doesn't seem to have an "output to file" option. This example shows two different ways of how you can save that command's output to a file. Method 1: Use Tcl For simplicity I'm going to use "ls -r", which outputs a list of all regions in a geometry database. I'd like to save that list of regions to a file named myfile.txt (could just as easily have been something like C:\\something.txt), perhaps with a simple header: mged> ls -r extrude.r grass.c grass.c.r grass.r grass.r.r ground.r mypoly.s mypoly.s.r sph.r sphere.r mged> open myfile.txt {WRONLY CREAT} file11 mged> puts file11 "Here are my regions:" mged> puts file11 \[ ls -r \] mged> close file11 mged> exec cat myfile.txt Here are my regions: extrude.r grass.c grass.c.r grass.r grass.r.r ground.r mypoly.s mypoly.s.r sph.r sphere.r After you "open" the file, it gives you a little handle name on the file that you can then use to write stuff into the file. If you didn't want to remember the name of the handle, you could save it to a variable instead like this: mged> set blah \[ open myfile.txt {WRONLY CREAT} \] file11 mged> puts $blah "Yet another list of my regions:" mged> puts $blah \[ ls -r \] mged> close $blah Method 2: Use MGED command-mode and save the output Another solution that is a lot more simple, but requires you to be slightly more comfortable with a UNIX or MSDOS command line is to run mged in "command-mode" where it will just run a single command and then quit. Also, mged will need to be in your path or in the current directory (on Windows). By redirecting the output, you can capture the contents to a file. For example, say you wanted to save the output of the "help" command (which lists available commands and a brief description) to a file: mged -c somefile.g help > myfile.txt 2>&1 That example was if you're using a posix-style shell like bash. If you are using tcsh, it would be: mged -c somefile.g help >& myfile.txt You could have just as easily run "ls -r" instead of "help" as in the preceeding example too. Overally, hopefully you'll find one of these two approaches useful or interesting. Cheers! Sean |