package kalang.script;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import kalang.lang.Script;

/**
 *
 * @author Kason Yang
 */
public abstract class ShellScript extends Script {
    
    protected int exec(String command,String... arguments) throws IOException{
        String[] list = new String[arguments.length+1];
        list[0] = command;
        if(arguments.length>0){
            System.arraycopy(arguments, 0, list, 1, arguments.length);
        }
        ProcessBuilder pb = new ProcessBuilder(list);
        pb.inheritIO();
        Process p = pb.start();
        try {
            p.waitFor();
        } catch (InterruptedException ex) {
            
        }
        return p.exitValue();
    }
    
    protected int exec(String command) throws IOException{
        return exec(command,new String[0]);
    }

}

@@ -32,27 +32,20 @@
 java.io.
-IOException
+File
 ;%0Aimport
@@ -54,86 +54,89 @@
 ava.
-util.logging.Level;%0Aimport java.util.logging.Logger;%0Aimport kalang.lang.Script
+io.IOException;%0Aimport kalang.lang.Script;%0Aimport org.apache.commons.io.FileUtils
 ;%0A%0A/
@@ -218,20 +218,625 @@
 cript %7B%0A
+%0A
     
+public final static String DEFAULT_ENCODING = %22utf8%22;%0A%0A    protected String readText(File file, String encoding) throws IOException %7B%0A        return FileUtils.readFileToString(file, encoding);%0A    %7D%0A%0A    protected String readText(File file) throws IOException %7B%0A        return readText(file, DEFAULT_ENCODING);%0A    %7D%0A%0A    protected void writeText(File file, String data, String encoding) throws IOException %7B%0A        FileUtils.writeStringToFile(file, data, encoding);%0A    %7D%0A%0A    protected void writeText(File file, String data) throws IOException %7B%0A        writeText(file, data, DEFAULT_ENCODING);%0A    %7D%0A
 %0A    pro
@@ -866,16 +866,17 @@
 command,
+ 
 String..
@@ -898,32 +898,33 @@
 rows IOException
+ 
 %7B%0A        String
@@ -964,9 +964,11 @@
 ngth
-+
+ + 
 1%5D;%0A
@@ -1004,16 +1004,17 @@
       if
+ 
 (argumen
@@ -1026,11 +1026,14 @@
 ngth
-%3E
+ %3E 
 0)
+ 
 %7B%0A  
@@ -1304,28 +1304,16 @@
 n ex) %7B%0A
-            
 %0A       
@@ -1351,20 +1351,16 @@
 ;%0A    %7D%0A
-    
 %0A    pro
@@ -1409,16 +1409,17 @@
 xception
+ 
 %7B%0A      
@@ -1440,16 +1440,17 @@
 command,
+ 
 new Stri

add methods:readText,writeText