The at command of Windows completes the scheduled task, that is, schedule batch job.
For how to use at, you can find Windows Help.
The class calls the cmdexecute class already described in this blog.
In Windows XP, run the AT command to periodically run the custom batch processing file databasebackup. bat.
Batch File Content: mysqldump -- user = root -- Password = XXXXX dbname> % 1. SQL
Call the MySQL Database Backup command. % 1 indicates passing in a parameter from the command line as the output file name.
The doscommand line finally called by the program is:
At 21:10:00/every: 26,27 D:/databasebackup. Bat output
/*
* Created on 2005/07/26
*
* Todo to change the template for this generated file go
* Window-preferences-Java-code style-code templates
*/
Import cmdexecute;
Import java. Io. ioexception;
/**
* Set schedule bat by
* @ Author Tyrone
*
*/
Public class atsetting {
Private int argslen = 1;
Private string [] arguments = NULL;
Private string cmd = "";
Private string directory = "";
Private string time = "";
Private string weekday = "";
Private string date = "";
Private int getargslen (){
Return this. argslen;
}
Private string gettime (){
Return this. Time;
}
/**
* The format is hh: mm: SS
* @ Param time
*/
Public void settime (string time ){
This. Time = time;
Argslen ++;
}
Private string getdate (){
Return this. date;
}
// If weekday! = "", Date will be omited.
Public void setdate (string date ){
If (this. getweekday () = ""){
This. Date = date;
Argslen ++;
}
}
Private string getweekday (){
Return this. weekday;
}
// Weekday = {M, T, W, Th, F, S, Su }.
Public void setweekday (string weekday ){
This. weekday = weekday;
Argslen ++;
}
/**
* @ Return returns the directory.
*/
Private string getdirectory (){
Return directory;
}
/**
* @ Param directory the directory to set.
*/
Public void setdirectory (string property1 ){
This. Directory = property1;
}
/**
* @ Return returns the cmd.
*/
Private string getcmd (){
Return this. CMD;
}
/**
* @ Param cmd the CMD to set.
*/
Public void setcmd (string property1 ){
This. cmd = property1;
Argslen ++;
}
/**
* @ Return returns the argument.
*/
Private string [] getarguments (){
Return arguments;
}
/**
* @ Param argument the argument to set.
*/
Public void setarguments (string [] property1 ){
This. Arguments = property1;
Argslen = argslen + property1.length;
}
/**
* Run at command
* @ Return
*/
Public String run (){
If (this. getargslen () = 0 ){
Return "";
}
// Organize ARGs
Int ARGs = 0;
String [] cmd = new string [This. argslen];
CMD [ARGs] = "";
If (this. gettime () = ""){
Return "No time set ";
} Else {
ARGs ++;
CMD [ARGs] = This. gettime ();
}
If (this. getweekday ()! = ""){
ARGs ++;
CMD [ARGs] = "/every:" + this. getweekday ();
} Else {
If (this. getdate ()! = ""){
ARGs ++;
CMD [ARGs] = "/every:" + this. getdate ();
}
}
String dir = This. getdirectory ();
If (Dir! = ""){
If (! Dir. endswith ("//")){
Dir = dir + "//";
}
If (this. getcmd () = ""){
Return "no command set ";
} Else {
ARGs ++;
CMD [ARGs] = dir + this. getcmd ();
}
}
If (this. getarguments ()! = NULL ){
For (INT I = 0; I <this. getarguments (). length; I ++ ){
CMD [ARGs + 1 + I] = This. getarguments () [I];
}
}
String result = "";
Cmdexecute exec = new cmdexecute ();
Try {
Exec. Run (CMD, null );
} Catch (ioexception ex ){
Ex. printstacktrace ();
}
Return result;
}
Public static void main (string [] ARGs ){
// MySQL backup
Atsetting at = new atsetting ();
At. setcmd ("databasebackup. Bat ");
At. setdirectory ("D ://");
At. setarguments (ARGs );
At. settime ("21:10:00 ");
// At. setweekday ("T ");
At. setdate ("26,27 ");
String result = at. Run ();
System. Out. println (result );
}
}