コード:のRuntime.exec()は出力4 'ストリート' プロセス実行
for (int i=0; i < NUM_STREETS; i++) {
Process process = runtime.exec("java -classpath \\bin trafficcircle.Street 1 2");
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null && !line.isEmpty()) {
System.out.println(line);
System.out.flush();
}
InputStream es = process.getErrorStream();
InputStreamReader esr = new InputStreamReader(es);
BufferedReader br2 = new BufferedReader(esr);
while ((line = br2.readLine()) != null && !line.isEmpty()) {
System.out.println(line);
System.out.flush();
}
int exitVal = process.waitFor();
System.out.println("Process exitValue: " + exitVal);
}
'ストリート' である:
public class Street {
/**
* @param args
* 0 - Simulation run time
* 1 - Flow time interval
*/
public static void main(String[] args) {
System.out.println(args[0]);
System.out.println(args[1]);
System.out.flush();
}
}
プリントアウト:
Error: Could not find or load main class trafficcircle.Street
Process exitValue: 1
Error: Could not find or load main class trafficcircle.Street
Process exitValue: 1
Error: Could not find or load main class trafficcircle.Street
Process exitValue: 1
Error: Could not find or load main class trafficcircle.Street
Process exitValue: 1
Eclipseプロジェクトの「Street.class」はパッケージ内の\ binにあるtrafficcircle。 Runtime.execが見つからなければ最初に不平を言うだろうと思ったんだけど...これで何ができるの?
System.out.flush()を試したことがありますか?両端で? – leonm
ちょうど編集したように、しかしまだ何もしませんでした。 – Rooster
プロンプトからそのコマンドを実行しようとしましたか?サブプロセスのエラーストリームを読んで、有用なものがそのプロセスに印刷されているかどうかを確認してください。 –