Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Host Commands from Java

User_resUNov 19 2010 — edited Nov 19 2010
Hello everyone,

I'm trying to run openVMS host commands via Java using the code listed below, which essentially runs the following host commands, each in turn:

terry :== "hello"
sho sym terry
sho log robin4

I've tried a few other commands as well, but the ones which assign variables (such as the terry example above), never work, either producing no output as in the example above, or if I did

define/group "hello" terry

would produce:

DCL-W-NOCOMD, no command on line - reenter with alphabetic first character

So commands that don't print anything to the screen are the ones that are causing problems (they're just setting variables or what not).

Does anyone have any ideas as to how to get these commands working via java? I really don't know what to think..I've tried checking the format of the commands I'm trying to do, and it's not down to that - the host command I'm running is right and works if done directly.

Please help! Thank you so much in advance.

Robin

import java.io.*;
public class Host {
public static void executeCommand(String command) {
String s = "hello";
String s2 = "sho log robin4";
String s3 = "assign/system "+command+"hello"+command+" robin5";
try {
String[] finalCommand;
System.out.println(System.getProperty("os.name"));
finalCommand = new String[3];
finalCommand[0] = "terry :== \"hello\"";
finalCommand[1] = "sho sym terry";
finalCommand[2] = s2;
// }

for(int i = 0;i< finalCommand.length; i++){
// Execute the command...
final Process pr = Runtime.getRuntime().exec(finalCommand);

// Capture output from STDOUT...
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {

System.out.println("stdout: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
}
br_in.close();
} catch (IOException ioe) {
System.out.println("Error printing process output.");
ioe.printStackTrace();
} finally {
try {
br_in.close();
} catch (Exception ex) {}
}

// Capture output from STDERR...
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("stderr: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
}
br_err.close();
} catch (IOException ioe) {
System.out.println("Error printing execution errors.");
ioe.printStackTrace();
} finally {
try {
br_err.close();
} catch (Exception ex) {}
}
}
}
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
}



}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2010
Added on Nov 19 2010
2 comments
509 views