TFM-4.3-Reloaded/src/me/StevenLawson/TotalFreedomMod/TFM_RunSystemCommand.java
Steven Lawson fce0ca3498 Added TFM_Log class to organize logging. !!STILL UNSTABLE!!
Will complete JeromSar merge next commit, using these loggers.
2012-09-15 13:01:43 -04:00

61 lines
1.6 KiB
Java

package me.StevenLawson.TotalFreedomMod;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TFM_RunSystemCommand implements Runnable
{
private final String command;
private final TotalFreedomMod plugin;
public TFM_RunSystemCommand(String command, TotalFreedomMod plugin)
{
this.command = command;
this.plugin = plugin;
}
@Override
public void run()
{
try
{
final ProcessBuilder childBuilder = new ProcessBuilder(command);
childBuilder.redirectErrorStream(true);
childBuilder.directory(plugin.getDataFolder().getParentFile().getParentFile());
final Process child = childBuilder.start();
final BufferedReader reader = new BufferedReader(new InputStreamReader(child.getInputStream()));
try
{
child.waitFor();
String line;
do
{
line = reader.readLine();
if (line != null)
{
TFM_Log.info(line);
}
}
while (line != null);
}
finally
{
reader.close();
}
}
catch (InterruptedException ex)
{
TFM_Log.severe(ex.getMessage());
}
catch (IOException ex)
{
TFM_Log.severe(ex.getMessage());
}
catch (Throwable ex)
{
TFM_Log.severe(ex);
}
}
}