Recent Notes

Displaying keyword search results 1 - 4
Created by Dr. Xi on March 02, 2011 11:39:18    Last update: March 09, 2011 12:19:30
Some peculiarities about Java PrintWriter: PrintWriter never throws any exceptions. From JavaDoc : Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError(). When error occurs, you'll never know anything more than that it occured, because checkError returns boolean. When a character is out of the range of the character encoding of the PrintWriter, it prints a question mark (?). But this is not an error. Test code: import java.io.*; public class TestPrintWri... Latin1 test result: java TestPrintWriter iso-8859-1 | od -bc 000000... UTF-8 test result: java TestPrintWriter utf-8 | od -bc 0000000 141... Also, the constructor throws a FileNotFoundException when you try to write to a...
Created by mak on March 04, 2011 14:17:32    Last update: March 04, 2011 14:18:35
To create a zipfile in python: Code: #!/usr/local/bin/python import zipfile #... Test unzip -l test.zip Archive: test.zip Lengt... To read a zipfile in python: Code: #!/usr/local/bin/python import zipfile #...
Created by Dr. Xi on December 05, 2009 20:12:16    Last update: December 05, 2009 20:46:45
It's quite easy for Perl to open a pipe and read from it: $file = "nospace.txt"; open(IN, "cat $file |") ... But the code breaks when the file name contains a space: # This does not work! $file = "yes space.txt"; ... On Windows, these don't work either: # This does not work! $file = "yes space.txt"; ... You need to use a technique called Safe Pipe Opens : $file = "yes space.txt"; $prog = "cat"; ...
Created by Dr. Xi on October 06, 2008 22:48:08    Last update: October 06, 2008 22:50:11
A first attempt would be to create an input file like this: userid password shell_command1 shell_... and feed the lines to the telnet client: cat telnet_input.txt | telnet remote_host #... However, you'll learn soon enough that it doesn't work. You get output like this: Trying 192.168.159.128... Connected to bash... What's happening? The telnet client depleted all input before the remote host had a chance to respond. Since there's no more input, the telnet client initiated to close the connection. Adding a delay between the commands makes it work: (echo userid sleep 10 echo password ... How much time to sleep between commands is just guesswork. You can use Expect to provide more control over the automated session: #!/usr/bin/expect # timeout script aft......