2012-02-29 15 views
0

私は次のコードを使用してErrorStreamを取得しています。大きなBig Runtime.Exec操作でErrorStreamを取得する方法

shellinput[0] = "/system/xbin/dd if=/dev/zero of="; 
shellinput[1] = newvfspath; 
shellinput[2] = "/gtj.img bs=1000000 count="; 
shellinput[3] = gtjsize; 
System.out 
     .println("Error Code (making new " 
       + newvfspath 
       + "/gtj.img) : 
      + errorstreamReader(shellinput)" 
private String errorstreamReader(String[] shellinput) { 
    InputStream inputstream = null; 
    String esrval = null; 
    System.out.println("Entering errorstreamReader"); 
    //hack to prevent executing null 
    for (int i = 0; i <= 3; i++) { 
     if (shellinput[i] == null) { 
      shellinput[i] = ""; 
     } 
    } 
    try { 
    System.out.println("Executing " + shellinput[0] 
       + shellinput[1] + shellinput[2] + shellinput[3]); 
     inputstream = Runtime 
       .getRuntime() 
       .exec(shellinput[0] + " " + shellinput[1] + " " 
         + shellinput[2]).getErrorStream(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    InputStreamReader inputstreamreader = null; 
    try { 
     inputstreamreader = new InputStreamReader(inputstream); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    try { 
     esrval = new BufferedReader(inputstreamreader).readLine(); 
    } catch (IOException e1) { 
     e1.printStackTrace(); 
    } 
    return esrval; 
} 

しかし、これで問題は/system/xbin/dd if=/dev/zero of=./mnt/sdcard/cimages_2/gtj.img bs=1000000 count=100であることが8秒のようにとり、かなり大規模な操作です。だから実行していない。これをどうやって解決するのですか?

編集:

問題は、それが大きな操作であることはなかったです。私はそれを把握する。ありがとう。

+0

答えとしてあなたのソリューションを投稿してください。 – talnicolas

+0

プロセスにかかる時間にかかわらず、データが利用可能なときに入力ストリームから読み込むことができるはずです。では、実行していないものは何ですか?詳細を教えていただけますか? –

答えて

0

は、これはそれを修正:

shellinput[0] = "/system/xbin/dd if=/dev/zero of="; 
shellinput[1] = newvfspath; 
shellinput[2] = "/gtj.img bs=1000000 count="; 
shellinput[3] = gtjsize; 
System.out 
     .println("Error Code (making new " 
       + newvfspath 
       + "/gtj.img) : 
      + errorstreamReader(shellinput)" 
private String errorstreamReader(String[] shellinput) { 
    InputStream inputstream = null; 
    String esrval = null; 
    System.out.println("Entering errorstreamReader"); 
    //hack to prevent executing null 
    for (int i = 0; i <= 3; i++) { 
     if (shellinput[i] == null) { 
      shellinput[i] = ""; 
     } 
    } 
    try { 
    System.out.println("Executing " + shellinput[0] 
       + shellinput[1] + shellinput[2] + shellinput[3]); 
     inputstream = Runtime 
       .getRuntime() 
       .exec(shellinput[0] 
       + shellinput[1] + shellinput[2] + shellinput[3]).getErrorStream();// this fixed it, typo 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    InputStreamReader inputstreamreader = null; 
    try { 
     inputstreamreader = new InputStreamReader(inputstream); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    try { 
     esrval = new BufferedReader(inputstreamreader).readLine(); 
    } catch (IOException e1) { 
     e1.printStackTrace(); 
    } 
    return esrval; 
} 
関連する問題