電子書籍の厳選無料作品が豊富!

現在、eclipseでJAVAをやっています。(環境はwindows XPです。)
JAVAから構文解析器(cabocha)を用いて、文章を解析させたいと考えています。
[やりたいこと]
1.INPUTファイルを自動生成(ファイルA.txt)をする。
2.ファイルAの内容をコマンドプロンプトからCabochaを実行し、
  解析を行う。
3.その結果をOUTPUTファイル(ファイルB.txt)に保存し、出力させる。
そこで、2番について教えていただきたいのですが、JAVAからコマンドプロンプロトを実行し、
cd c:\program files\cabocha\bin
cabocha.exe -f1 input.txt --output=output.txt
の2行をペーストし、cabochaを実行させたいのですが、どのようにすればよいのでしょうか。
自分がわかっているプログラム以下のところまでです。
[プログラム]
public static void main(String[] args) throws IOException{
File file1 = new File("C:\\Program Files\\CaboCha\\bin\\input.txt");
try{
String str=null;
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader buffreader =new BufferedReader(reader);
System.out.println("文字を入力してください。");
str = buffreader.readLine();
PrintWriter pr =new PrintWriter(new BufferedWriter(new FileWriter("C:\\Program Files\\CaboCha\\bin\\input.txt")));
pr.write(str);
System.out.println(str+"が書き込まれました。");
pr.close();

Runtime rt = Runtime.getRuntime();
Process pro = rt.exec("C:\\WINDOWS\\system32\\cmd.exe");
}
誰かわかる方、ご教授お願いいたします。

A 回答 (1件)

>の2行をペーストし、cabochaを実行させたい


この2行をペーストするのが目的ではなくて、単に"c:\program files\cabocha\bin"を作業ディレクトリにしてコマンドを実行したいのではないでしょうか。単純に
Runtime#exec("cabocha.exe -f1 input.txt --output=output.txt", null, new File("c:\program files\cabocha\bin"));
では駄目ですか?
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!