Get cmd command, accurate to minute
- Package lihan;
- Import java. Io. bufferedreader;
- Import java. Io. file;
- Import java. Io. filereader;
- Import java. Io. ioexception;
- Import java. Io. inputstreamreader;
- Import java. util. arraylist;
- Import java. util. List;
- /**
- * Get tomcat running time
- * @ Author Li Yun
- *
- */
- Public class readruntime {
- /**
- * Use testing)
- * @ Param ARGs
- * @ Throws ioexception
- */
- Public static void main (string [] ARGs) throws ioexception {
- Try {
- String STR = readsystemstarttime ();
- System. Out. Print (STR );
- } Catch (interruptedexception e ){
- // Todo automatically generates catch Blocks
- E. printstacktrace ();
- }
- }
- Public static string readsystemstarttime () throws ioexception,
- Interruptedexception {
- Process = runtime.getruntime(cmd.exe C (
- "CMD/C net statistics workstation ");
- String startuptime = "";
- Bufferedreader = new bufferedreader (
- New inputstreamreader (process. getinputstream ()));
- Int I = 0;
- String timewith = "";
- While (timewith = bufferedreader. Readline ())! = NULL ){
- If (I = 3 ){
- System. Out. println (timewith );
- // Startuptime = timewith. substring (x, y );
- Startuptime = timewith;
- }
- I ++;
- }
- Process. waitfor ();
- Return startuptime;
- }
- }
Output result:
Statistics start
Statistics start