Javaコードからコマンドラインを実行しようとしました。
public void executeVcluto() throws IOException, InterruptedException {
String command = "cmd /c C:\\Users\\User\\Downloads\\program.exe C:\\Users\\User\\Downloads\\file.txt 5 >> C:\\Users\\User\\Downloads\\result.txt";
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
if (process.exitValue() == 0) {
System.out.println("Command exit successfully");
} else {
System.out.println("Command failed");
}
}
ただし、出力結果を書き込むべきファイルresult.txtは作成されません。Windowsでcmdからこのコマンドを実行すると、ファイルが作成され、結果が書き込まれます。Command exit successfully というメッセージが表示されます。誰かが私を助けることができますか?