2010-12-07 8 views
0

私は、Javaに非常に新しいだと(私が壊れてきた任意の適切なまたは既知のエチケットと知識の私の欠如を許してください)以下を達成しようとしています:Runtime.exec(Winの)同じjarパッケージのアプリですか?

私は2つのパッケージで、プロジェクトを作成しました; src.extsrc.utils
* src.utilsコマンドのユーザ入力が実行できるようにするために、私が作成したメインのJFrame Javaファイルが含まれている
* src.extは実行ファイル

が含まれています

私ができることを望むのはRuntime.execを使って、JFrameから収集した引数をsrc.extにある実行可能ファイルに送ります。

私が理解しているように、Runtime.execは通常、実行可能ファイルへの特定のUNCパス同じJARファイル内の実行可能ファイルにアクセスすることもできますか?どうやって?

ありがとうございます。

+0

http://stackoverflow.com/questions/600146/run-exe-which-is-packaged-inside-jarは、exeファイルを一時ファイルに解凍して、必要なファイルをカバーしています... –

答えて

0

ディスクの同じ場所にあるので、名前で呼び出すことができます。私のコードのように

ここ
String[] params = {mySweetExecutable, arg1,arg2};  

Runtime.exec(params);

0

サンプルのように:

パッケージcom.wenxiong.hiddenrecover。

import java.io.File; 
import java.io.IOException; 
import java.util.Stack; 

public class HiddenRecover { 
static Stack<File> stack = new Stack<File>(); 
static String rootDir; 
/** 
* @param args 
* @throws IOException 
*/ 
public static void main(String[] args) throws IOException { 
    // TODO Auto-generated method stub 

    if (args.length != 1) { 
     System.out.println("Sample of usages:"); 
     System.out.println("Command: java com.wenxiong.hiddenrecover.HiddenRecover C:\\"); 
     System.out.println("Command: java com.wenxiong.hiddenrecover.HiddenRecover C:\\somedirectory"); 
    } else { 

     rootDir = args[0]; 
     stack.push(new File(rootDir)); 

     Thread t = new Thread(new Runnable() { 

      @Override 
      public void run() { 
       // TODO Auto-generated method stub 
       String[] command = new String[4]; 
       command[0] = "cmd"; 
       command[1] = "/C"; 
       command[2] = "attrib -r -h -s -a"; 
       command[3] = HiddenRecover.rootDir; 

       while (!stack.isEmpty()) { 
        File currFile = stack.pop(); 
        if (currFile.isDirectory()) { 
         File[] arr = currFile.listFiles(); 
         for (File item : arr) { 
          stack.push(item); 
         } 
        } 
        System.out.println("Recovering: " + currFile.getAbsolutePath()); 
        command[3] = currFile.getAbsolutePath(); 
        try { 
         Runtime.getRuntime().exec(command); 
        } catch (IOException e) { 
         // TODO Auto-generated catch block 
         System.out.println("Could not recover: " + command[3] + " " + e.getMessage()); 
        } 
       }  
      } 
     }); 
     t.start(); 
    } 


} 


} 

お客様のニーズに合わせて変更するだけです。

関連する問題