Run .sh File in Java Code on Linux Machine -
my task: 1 - read excel file, parse , save data in txt file. 2 - read txt file , pass batch.sh file. batch.sh file 1 thing, picks data above mentioned txt file , save in database's table.
when run batch.sh file terminal(and give txt file), works fine. inserts records in database want.
problem is, when want same java code, batch.sh file not work. , also, no exception thrown.
some explanation: using java 7, oracle, sql-loader, linux.
additional information: if rename batch.sh file batch.bat file , run in windows environment, works fine. batch.sh file works fine if executed terminal. problem is, not working java code.
i listing java code snippet, batch.sh file , control.txt file following task.
java code:
try{ string target = new string("/path/to/batchfile/batch.sh"); runtime rt = runtime.getruntime(); process proc = rt.exec(target); proc.waitfor(); }catch(exception e){ log.error("exception occured message : "+e.getmessage()); }
batch.sh:
sqlldr username/password@sid control='/path/to/batchfile/control.txt' log='/path/to/batchfile/results.log' bad='/path/to/batchfile/badfile.bad' errors=5000
control.txt:
options ( skip=1 ) load data infile '/path/to/batchfile/txtfiledata.txt' truncate table table_name fields terminated "," ( column_name "replace(:column_name,'-','')" )
p.s: have read many post regarding same issue, , tried every solution, non working. current example of java code taken stackoverflow thread.
any highly appreciated.
you'd want runtime.getruntime.exec(new string[]{"/bin/bash", "-c", "/path/to/script.txt"})
see here: how execute command parameters?
Comments
Post a Comment