【发布时间】:2018-05-15 13:46:46
【问题描述】:
如何使用java程序执行oraenv脚本?我如何从 Linux 终端执行。
[oracle@DeltaLinOraASM2 tmp]$ . oraenv
ORACLE_SID = [oracle] ? deltaasm
The Oracle base has been set to /u01/app/oracle
[oracle@DeltaLinOraASM2 tmp]$
我的oraenv 脚本文件包含以下内容:
export ORACLE_HOME=/opt/oracle/product/12.2.0.1/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=deltaasm
如何使用java程序执行oraenv文件。
它在问 ORACLE_SID= 吗?执行脚本后。但是从程序中它没有被执行。
public class App2 {
public static String RunLinuxGrepCommand(String command) {
String line = null;
String strstatus = "";
try {
String[] cmd = { "/bin/sh", "-c", command };
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = in.readLine()) != null) {
strstatus = line;
}
in.close();
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.flush();
String stackTrace = sw.toString();
int lenoferrorstr = stackTrace.length();
if (lenoferrorstr > 500) {
strstatus = "Error:" + stackTrace.substring(0, 500);
} else {
strstatus = "Error:" + stackTrace.substring(0, lenoferrorstr - 1);
}
}
System.out.println("strstatus" + strstatus);
return strstatus;
}
public static void main(String[] args) throws IOException {
String str = ". oraenv ; deltaasm ";
App2.RunLinuxGrepCommand(str);
}
}
【问题讨论】:
标签: java linux oracle shell unix