Re: Some Noob Questions
"Kyle T. Jones" <KBfoMe@realdomain.net> writes:
Need to do some System Administration work that requires occasional
scripting - I know Java isn't a scripting language, but would it work
You can use Java for ?meta-scripting?.
Assume, for example, that you want to download:
http://www.example.invalid/page000.html
http://www.example.invalid/page001.html
....
http://www.example.invalid/page621.html
to ?C:\directory? under Windows, but in this very moment you
cannot remember the wget option for this nor the syntax of the
FOR-loop command of the shell or use a version of Windows
without an appropriate shell FOR loop. Running the following
might sometimes do the job without any additional user action.
It runs up to 999, assuming that we do not yet know that the
last page number is 621. The poor man's shell loop:
public class Main
{ public static void main( final java.lang.String[] args )
throws java.lang.Throwable
{ final java.io.File outFile = new java.io.File( "generated.bat" );
final java.io.PrintWriter out =
new java.io.PrintWriter( new java.io.FileOutputStream( outFile ), true );
out.println( "C:" );
out.println( "cd \"\\directory\\\"" );
for( int i = 0; i < 999; ++i )out.println
( "wget http://www.example.invalid/" +
java.lang.String.format( "%03d", i )+ ".html" );
out.close();
if( java.awt.Desktop.isDesktopSupported() )
java.awt.Desktop.getDesktop().open( outFile ); }}
(People who would like to encourage me to keep posting source
code to newsgroups can do so, by not quoting the complete
source code above, but just parts they directly refer to.)