dcsimg
pc shutdown via .java file
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, August 27, 2004 05:24 AM

how to shutdown a win pc through core java program.


how to execute dos commands in java file (not .bat file)




thank you,


With regards


Narasimha

Re: pc shutdown via .java file

Posted By:   Anonymous  
Posted On:   Friday, October 8, 2004 01:43 PM

In the future LatteLib (www.lattelib.com) will allow you to shut down or reboot a PC with one line of code. Stay tuned.

Re: pc shutdown via .java file

Posted By:   Michael_Decker  
Posted On:   Monday, August 30, 2004 12:32 AM

Please use seperate threads for seperate questions


Here is a sample Code for running a program:



// ----------------------------------------------------------------------------------------------

// RunProgram

// ----------------------------------------------------------------------------------------------

import java.lang.*; // RunTime and Process

import java.io.*; // OutputStream

import java.util.*; // Date



/**

* RunProgram

*

* Runs a program

*

*/

abstract class RunProgram

{

private Process runningProcess; // Save running process

private Runtime runTime; // Save used RunTimeEnviroment

private String command; // Save calling command

BufferedReader bufferedReader; // Needed for reading output

FileSave logFile;



/**

* Constructor

*

* Get RunTime-Enviroment

*

*/

public RunProgram(String command, FileSave logFile)

{

runTime = Runtime.getRuntime(); // Holt sich die RunTimeUmgebung

this.command = command; // Speichert auszuführenden Befehl

this.logFile = logFile;

}



/**

* runIt

*

* Run programm

*

* Exceptions:

* java.io.IOException

*/

public void runIt()

throws java.io.IOException

{

runningProcess = runTime.exec(command); // Startet das Programm

bufferedReader = getBufferedReader(runningProcess.getInputStream()); // Holt Ausgabe

}



/**

* getBufferedReader

*

* Schafft aus dem InputStream einen BufferedReader

* Indem mit Hilfe des InputStreams eine InputStreamReader kreiert wird,

* kann ein BufferedReader erstellt werden, welcher zeilenweise ausliest

*

* Parameter:

* InputStream des Prozesses

*

* Rückgabe:

* BufferedReader des InputStreams des Prozesses

*/

private BufferedReader getBufferedReader(InputStream inputStream)

{

return new BufferedReader(new InputStreamReader(inputStream));

}



/**

* writeLines

*

* Liest die Ausgabe des Programmes aus.

* Wertet diese dann aus und schreibt sie in angepasster Form in eine Datei

*

* Die Funktion muss überschrieben werde

*/

public abstract void writeLines()

throws java.io.IOException;



/**

* getTime

*

* Generiert die aktuelle Systemzeit als lesbaren String

*

* Rückgabe:

* Systemzeit in formatierter Form als String

*/

String getTime()

{

return (new java.text.SimpleDateFormat("yyyy.MM.dd HH:mm:ss")).format(new Date());

/*

* Formatiert die aktuelle Systemzeit in Jahr.Monat.Tag Stunden:Minuten:Sekunden

*/

}

}



AND WHY CAN IT NOT NORMALY FORMATED LIKE EVERY FORUM ELSE WITH PHPBB2 OR SO?! *ARG*

About | Sitemap | Contact