MCPcopy Create free account
hub / github.com/quentinhardy/odat / Java

Class Java

Java.py:10–336  ·  view source on GitHub ↗

Allow to use Java remotly

Source from the content-addressed store, hash-verified

8from Constants import *
9
10class Java (OracleDatabase):
11 '''
12 Allow to use Java remotly
13 '''
14 def __init__(self,args):
15 '''
16 Constructor
17 '''
18 logging.debug("Java object created")
19 OracleDatabase.__init__(self,args)
20 self.SOURCE_OS_COMMAND_CLASS = """
21CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "OSCommand" AS
22 import java.io.*;
23 public class OSCommand {
24 public static String executeCommand(String command) {
25 StringBuffer sb = new StringBuffer();
26 try {
27 String[] finalCommand;
28 if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
29 String systemRootvariable;
30 try {systemRootvariable = System.getenv("SystemRoot");}
31 catch (ClassCastException e) {
32 systemRootvariable = System.getProperty("SystemRoot");
33 }
34 finalCommand = new String[4];
35 finalCommand[0] = systemRootvariable+"\\\system32\\\cmd.exe";
36 finalCommand[1] = "/y";
37 finalCommand[2] = "/c";
38 finalCommand[3] = command;
39 } else { // Linux or Unix System
40 finalCommand = new String[3];
41 finalCommand[0] = "/bin/sh";
42 finalCommand[1] = "-c";
43 finalCommand[2] = command;
44 }
45 // Execute the command...
46 final Process pr = Runtime.getRuntime().exec(finalCommand);
47 pr.waitFor();
48 // Capture output from STDOUT
49 BufferedReader br_in = null;
50 try {
51 br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
52 String buff = null;
53 while ((buff = br_in.readLine()) != null) {
54 sb.append(buff); sb.append("\\n");
55 //try {Thread.sleep(100);} catch(Exception e) {}
56 }
57 br_in.close();
58 } catch (IOException ioe) {
59 sb.append("IOException in input stream: ").append(ioe.getMessage());
60 System.out.println("Error printing process output.");
61 ioe.printStackTrace();
62 } finally {
63 try {
64 br_in.close();
65 } catch (Exception ex) {}
66 }
67 // Capture output from STDERR

Callers 2

runjavaModuleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected