2011-10-21 04:17:02 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
|
|
|
public class TFM_RunSystemCommand implements Runnable
|
|
|
|
{
|
2012-03-06 19:25:22 +00:00
|
|
|
private final String command;
|
|
|
|
private final TotalFreedomMod plugin;
|
2011-10-21 04:17:02 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-09-15 17:01:43 +00:00
|
|
|
TFM_Log.info(line);
|
2011-10-21 04:17:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while (line != null);
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
reader.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (InterruptedException ex)
|
|
|
|
{
|
2012-09-15 17:01:43 +00:00
|
|
|
TFM_Log.severe(ex.getMessage());
|
2011-10-21 04:17:02 +00:00
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
2012-09-15 17:01:43 +00:00
|
|
|
TFM_Log.severe(ex.getMessage());
|
2011-10-21 04:17:02 +00:00
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
2012-09-15 17:01:43 +00:00
|
|
|
TFM_Log.severe(ex);
|
2011-10-21 04:17:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|