Call CL Program from Java Program

pts.
Tags:
Java
New Discussion Post

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Nlaney
    I'm not sure which issue you want help with, issuing a cl command, or passing a javascript variable to the java class. Issuing a cl command is pretty straightforward: Process p = Runtime.getRuntime().exec(cmd); System.out(new BufferedReader( new InputStreamReader(p.getInputStream()))); System.err(new BufferedReader( new InputStreamReader(p.getErrorStream()))); You need to output the input and error streams as shown to to flush the buffer, or the command might freeze. I'm interested how you're passing a javascript parameter to a java program. Cheers!
    0 pointsBadges:
    report
  • Kruegersck
    Do you have sample code of call a CL from Java? I am fairly new to Java and I have not found any good examples of doing this... Thanks!
    0 pointsBadges:
    report
  • Ashwinrayaprolu1
    /** * */ package com.ashwin; /** * @author Ashwin * */ public class WindowsExecCommand { public static Process proc = null; /** * @param command */ public static void execCommand(String command) { try { proc = null; String osName = System.getProperty("os.name"); String[] cmd = new String[3]; if (osName.equals("Windows 95")) { cmd[0] = "command.com"; cmd[1] = "/C"; cmd[2] = command; } else if (osName.contains("Windows")) { cmd[0] = "cmd.exe"; cmd[1] = "/C"; cmd[2] = command; } Runtime rt = Runtime.getRuntime(); System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]); if (command.endsWith(".bat")) { proc = rt.exec(command); } else { proc = rt.exec(cmd); } // any error message? StreamGobbler errorGobbler = new StreamGobbler(proc .getErrorStream(), "ERROR"); // any output? StreamGobbler outputGobbler = new StreamGobbler(proc .getInputStream(), "OUTPUT"); // kick them off errorGobbler.start(); outputGobbler.start(); // any error??? int exitVal = proc.waitFor(); System.out.println("ExitValue: " + exitVal); } catch (Throwable t) { t.printStackTrace(); }finally{ proc = null; } } } package com.ashwin; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; /** * @author Ashwin * */ class StreamGobbler extends Thread { InputStream is; String type; StreamGobbler(InputStream is, String type) { this.is = is; this.type = type; } public void run() { try { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) System.out.println(type + ">" + line); } catch (IOException ioe) { ioe.printStackTrace(); } } }
    30 pointsBadges:
    report
  • TomLiotta
    if (osName.equals(”Windows 95″)) { cmd[0] = “command.com”; cmd[1] = “/C”; cmd[2] = command; } else if (osName.contains(”Windows”)) { cmd[0] = “cmd.exe”; cmd[1] = “/C”; cmd[2] = command; } It might be pointed out that neither "Windows 95" nor "Windows" will be appropriate to run a CL program. Regardless, CL programs are called by Java just like any HLL program. It doesn't matter that it was compiled from CL. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following