私はシェルスクリプトを起動するはずのjavaプログラムを持っています。スクリプトには、順番に実行される6つのタスクが含まれています。 Javaプログラムがスクリプトを起動し、起動します(ログが表示されます)。しかし、10-15秒後に、シェルスクリプトの最初のタスクが完了する前に実行が停止します。奇妙なことは、スクリプトをターミナルで起動したときに正常に動作することです。スクリプトの実行中にプログラムがハングする危険を避けるために、別のスレッドで起動します。考えられる理由は何でしょうか?javaからシェルスクリプトを実行中 - 完了していないタスク
のJavaコード -
try {
log.info("run cmd - "+optionsRun);
String[] cmdLine = (String[]) optionsRun.toArray(new String[optionsRun.size()]);
Process process = Runtime.getRuntime().exec(cmdLine);
log.info("end run cmd " + this.getScriptPath());
//
// BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
// writer.write("mypwd");
// writer.flush();
// writer.close();
InputStream is = process.getErrorStream();
String error = inputStreamToStringValue(is);
log.trace("Eventual error was : " + error);
InputStream os = process.getInputStream();
String output = inputStreamToStringValue(os);
log.info("Eventual output was : " + output);
if (error!=null & error.length()>0) {
throw new ActionProcessingException("An error occurred when running the script :'"+this.getScriptPath()+"' with following error message : "+error);
}else {
log.info("Script run ended successfully.");
}
とシェルスクリプトは、このように見える - 事前に
#!/bin/sh
# ./publish <path-to-publish-home-folder> <workspace_id> <start_date> <end_date>
# ./publish <path-to-publish-home-folder> 100011 2010-01-06-12:00:00-CET 2012-01-14-19:00:00-CET
rm -f $1/publish.log
echo 'Start publish' >> $1/publish.log
echo $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 >> $1/publish.log
# lancement de l'export RDF du domaine
cd $1/1-export-domain
echo "Starting export domain with the command - ./export.sh $2" >> $1/publish.log
./export.sh $2
# lancement de l'export des translations du domaine
cd $1/2-export-trans
echo "Starting export domain(translated) with the command - ./export.sh $2" >> $1/publish.log
./export.sh $2
.....
.....
a couple of more steps like 1 and 2
....
おかげで、
publish.logにはどのような出力がありますか? –
更新:シェルスクリプトからリソースと時間のかかる作業を削除しようとしましたが、実行が完了しました。しかし、私は多くの時間(とリソース)を取るタスクを実行しようとすると、完了しません。シェルスクリプトがJavaプログラムから実行されているときに、自動タイムアウト(またはそれに類するもの)がありますか? – Ozyman
@AndrewFielden publish.logは、最初のタスクが開始されたことを示します。何もありません。私はそれぞれの仕事のために別々のログを持っています。 10秒または15秒後に、最初のタスクのロギングがただちに終了します(タスクは完了しません)。私は、Linuxのログからさらに情報を見つけることができるかどうかはわかりません。 – Ozyman