Run a Program Through my java program

Good day to you :)
I am wondering if there is anyway for me to run an executable (or batch) file though a program I made.
Thank you :)

Found it. thanks anyway :)

Similar Messages

  • Sorry if i sound foolish how to run an applet through a java application

    I am into java from last one month ank keep on exploring it in the want to
    recently i created a application cum applet in the same class like
    applet is doing its own task and there is a main method in the code
    that does entirly different task lets assume displaying *'s on the dos prompt the program is getting complied and belive it its running as desired
    but the only problem that i m facing if i use appletviewer Myclass.java
    only the appletprog is displayed
    and if i run java Myclass than only dos task is done
    may be it is sounding foolish for most of you but if i can get a way
    which will help me in excecuting only one of it and both of them run succesfully
    it tryied different ways to do it but was not succesful
    please do not get irreated if its bizzered but if you really have a solution for it .i will appreciate it
    thanking you

    Yes you can run an Applet from an application. The magic bit is providing an AppletContext and AppletStub!
    Here's how you start it:
            wpa = new WayPointsApplet(this);
            new AppletWrapper(wpa, 380, 320);Here's the class definition: (includes code for my application that can be ignored.
    // Define a wrapper class for the applet
    class AppletWrapper extends Frame implements AppletStub, AppletContext {
        Applet applet;
        // Constructor
        AppletWrapper(Applet a, int x, int y) { 
              applet = a; 
              setTitle(a.getClass().getName());
              setSize(x, y);
              Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
              setLocation((ss.width-x)/2, (ss.height-y)/2);
              add(a, "Center");
              a.setStub(this);
              // Trap window closing
              addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    // Test if Write left undone before exiting???
                    if(WayPoints.wpa != null) {
                      if(!WayPoints.wpa.okToExit())
                         return;           // Ignore
                    applet.stop();
                    applet.destroy();
                    if(WayPoints.debug || WayPointDefs.plot_debug) {
                      SaveStdOutput.stop();
                    System.exit(0);         // EXIT Program
              });  // end WindowListener
              a.init();
              show();
              a.start();
       } // end constructor
        // AppletStub methods
        public boolean   isActive() { return true; }
        public URL       getDocumentBase() { return null; }
        public URL       getCodeBase() {
            return WayPoints.currDir;
        public String    getParameter(String name) {
            if (name.equalsIgnoreCase("DEBUG")) {
                if (WayPoints.debug)
                    return "YES";
                else
                    return "NO";
            if(name.equals("PLOTDEBUG"))
                return (WayPointDefs.plot_debug ? "YES" : "NO");
            if (name.equalsIgnoreCase("SERVER"))
                return "NO";
            return "";
        public AppletContext getAppletContext() { return this; }
        public void      appletResize(int width, int height) {}
        // AppletContext methods
        public AudioClip getAudioClip(URL url) { return null; }
        public Image     getImage(URL url) { return null; }
        public Applet    getApplet(String name) { return null; }
        public Enumeration getApplets() { return null; }
        public void      showDocument(URL url) {}
        public void      showDocument(URL url, String target) {}
        public void      showStatus(String status) {}
    } // end class AppletWrapper

  • How to run a jar file using Java application.

    Hi all,
    I know that jar file can run using the following command, using the command prompt.
    java -jar jar-fileBut I don't know how to run that command through a Java code. Hope it's clear to you.
    So can you please explain how can I do it.
    Thanks,
    itsjava

    rayon.m wrote:
    The solution given by ropp appears to have nothing to do with what you asked about.Ok sir, I got the point.
    I've try a test as follows. But it doesn't give any output. Even not an exception.
            try {
                String[] temp = new String[]{"java", " -jar", " MainApp.jar"};
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(temp);
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);
                System.out.println("Temp_Values");
            catch(InterruptedException ex) {
                System.out.println(ex.getMessage());
            catch (IOException ex) {
                System.out.println(ex.getMessage());
            }I've debug and see, but the exitValue is even not exist at run time. Can you tell me where I'm going wrong.

  • Running perl programs through java.

    How do i run a perl program through java?
    arg.pl :
    while(<STDIN>)
    print;
    java program that I tried:
    import java.io.*;
    class runtime
        static Process p;
        static BufferedReader stdOutput;
        static BufferedWriter stdInput;
        public static void main(String args[]) throws IOException
            int i = 0;
            try{
                String cmd[] = new String[] {"perl","arg.pl"};
                p = Runtime.getRuntime().exec(cmd,null,new File("./"));
                stdOutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                stdInput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
            catch(Exception ex){
                System.out.println("Unable to initiate Process : " + ex);
            stdInput.write("abcd\n");
            stdInput.write("1234\n");
            stdInput.write("efgh\n");
            stdInput.write("5678\n");
            stdInput.close();
            System.out.println(stdOutput.readLine());
            System.out.println(stdOutput.readLine());
            System.out.println(stdOutput.readLine());
            System.out.println(stdOutput.readLine());
    }This works well. But I need to read the output line by line as and when i give the standard input line by line to it.
    I tried the following :
    import java.io.*;
    class runtime
        static Process p;
        static BufferedReader stdOutput;
        static BufferedWriter stdInput;
        public static void main(String args[]) throws IOException
            int i = 0;
            try{
                String cmd[] = new String[] {"perl","arg.pl"};
                p = Runtime.getRuntime().exec(cmd,null,new File("./"));
                stdOutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                stdInput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
            catch(Exception ex){
                System.out.println("Unable to initiate Process : " + ex);
            stdInput.write("abcd\n");
            stdInput.flush();
            System.out.println(stdOutput.readLine());
            stdInput.write("1234\n");
            stdInput.flush();
            System.out.println(stdOutput.readLine());
            stdInput.write("efgh\n");
            stdInput.flush();
            System.out.println(stdOutput.readLine());
            stdInput.write("5678\n");
            stdInput.flush();
            System.out.println(stdOutput.readLine());
            stdInput.close();
    }This doesn't work well. It just halts without any output.
    Can anyone help me?
    Edited by: Vijayakrishna on Dec 5, 2007 8:30 AM

    Let me be more specific.
    I want to use a class which will look something like this.
    import java.io.*;
    public class FindAnswer{
        Process p;
        BufferedReader stdOutput;
        BufferedWriter stdInput;
        public FindAnswer()
            try{
                String cmd[] = new String[] {"perl","arg.pl"};
                p = Runtime.getRuntime().exec(cmd,null,new File("./"));
                stdOutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                stdInput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
            catch(Exception ex){
                System.out.println("Unable to initiate Process. Error: " + ex);
        public String getAnswer(String question)
            String answer = question;
            try{
                stdInput.write(question + System.getProperty("line.separator"));
                stdInput.flush();
                answer = stdOutput.readLine();
            catch(Exception ex){
                System.out.println("Exception. Error: " + ex);
            return answer;
        public void close()
            if (p != null) {
                try {
                    if (p.getInputStream() != null)
                        p.getInputStream().close();
                    if (p.getOutputStream() != null)
                        p.getOutputStream().close();
                    if (p.getErrorStream() != null)
                        p.getErrorStream().close();
                catch (Exception e) {
                    System.out.println("Exception in Closing Streams - " + e);
    }The perl program takes lot of initialization time. I dont want to run the program foreach question i have. I'll just create an object to this class and find and answer by passing question to the object's getAnswer method. Here, I dont know all the questions in the beginning itself. I'll know one by one only and I should find answer without terminating the process.
    Kindly help me in this.

  • Running a Unix Script through a Java Program

    Hi !!!!!!!!! Can anybody plz suggest me an approach for the following queries -
    1.  How to execute a unix script through a java program ?
      2.  How to send the o/p of the script to a java program so that it can be used .

    import java.io.*;
    public RunScript
       public static void main(String args[])
          try
              Process p = Runtime.getRuntime().exec("script.sh");
              BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));     
              while ((line = input.readLine()) != null)
                 System.out.println(line);
              input.close();
          catch(Exception e)
              e.printStackTrace();

  • Running OpenSSL command through Java Program

    How do I execute openssl commands through a java program? Any packages or wrapper classes are there? Please help.
    Thanks.

    Hi!
    What do you mean execute commands? Like: "openssl x509 -in cert.pem -out certout.pem" ??
    In that case you can just try the following:
    import java.lang.Runtime;
    try {
    Runtime.getRuntime().exec("openssl x509 -in cert.pem -out certout.pem");
    }catch (Exception e) {
    e.printStackTrace();
    ........

  • How to run the jmeter through java program

    i wnat interact jmeter through my java program
    i will pass values to jmeter through my java program
    i wnat retrive the results from jmeter to my java program

    Read the manual.

  • Is there any way to close an IE browser on XP through a Java Program

    Hi All,
    I am working on an application which has a web form with various feilds in it, on selecting the fields and clicking submit, the form will launch a WinRunner application in a remote machine and runs a test. For this I am using Tomcat webserver (V4.0.1). Now the problem I have is, when I submit the form, and WinRunner Launches on the remote machine (which has Operating System XP), should not already have any Browser windows open on it. So, to ensure that no browser windows are open, Initially in my Java Program I want to write a code which cleans up all the OPEN Browser windows on that machine.
    Can any one help me out in finding a way of closing the IE browser windows on a XP machine through a Java program. (There is a servlet in the Tomcat webserver which launches the application based on the browser request). Tomcat is installed on the machine where WinRunner will be launched, So my browser request goes to that machine directly.
    Thank you very much,
    Ramesh Babu M.V.

    You can call some program (via Runtime.exec) that kills all IEXPLORE.EXE processes (ugly but could work for you). For instance, there is a program called kill.exe that you can try getting somewhere. My version of KILL.EXE is really old and somewhat buggy (killed all IEXPLORE.EXE processes but one in my Windows 2003 machine), so try checking if there's some newer version anywhere.
    C:\>kill -?
    Microsoft (R) Windows NT (TM) Version 3.5 KILL
    Copyright (C) 1994-1998 Microsoft Corp. All rights reserved
    usage: KILL [options] <<pid> | <pattern>>*
               [options]:
                   -f     Force process kill
               <pid>
                  This is the process id for the task
                   to be killed.  Use TLIST to get a
                   valid pid
               <pattern>
                  The pattern can be a complete task
                  name or a regular expression pattern
                  to use as a match.  Kill matches the
                  supplied pattern against the task names
                  and the window titles.

  • How to implement a print screen through a java program rather than a keyboa

    help needed urgently to make a college project.
    have to capture whatsoever is on the client screen
    and sent it to to a server program where it will be made visible on a frame or panel.
    this is to be done without the client ever knowing it.
    so needed to implement a printscreen command using java code and put it in a program(also how to make
    the .class file containing this code run in the background all the time since the client comp starts till it is shut down without the client ever knowing it)
    e mail: [email protected]

    <pre>
    hartmut
    i need help.
    i've recently started using the web to learn more about java.your reply was very discouraging.
    the proff. just wants a decent project.
    but i want to make this project to improve my java networking skills.
    if you can help , please tell me how to implement a printscreen through a java program rather than a keyboard.
    I'll be very grateful to you if you can help me in this regard, but please dont send a dissapointing response like the previous one.
    mail: [email protected]
    </pre>

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • Error Message: A main Java class needs to be specified to run the program.

    Hi,
    I am adding a program object to cms using java program, and trying to run it. I am getting an error message like
    Error Message: A main Java class needs to be specified to run the program.
    Could you please help me on this., please find the pasted program object pasted below
    public class MoveReports   {
    public void run(IEnterpriseSession enterpriseSession, IInfoStore infoStore,
                   String[] args) throws SDKException {
        int objectSize = ;
        String cms = "";
         String username = "";
         String password = "";
         String auth = "";
        try {
              ISessionMgr sm = CrystalEnterprise.getSessionMgr();
             enterpriseSession = sm.logon(username, password, cms, auth);
             IInfoStore oInfoStore=(IInfoStore)enterpriseSession.getService("", "InfoStore");
                 IInfoObjects iObjects = null;
                   iObjects = oInfoStore.query("Select * from CI_INFOOBJECTS where SI_PARENTID = 44104 AND SI_PROGID LIKE '%CrystalEnterprise.Excel%'");
                   // Getting total number of reports
                   objectSize = iObjects.size();
                   if(objectSize > 0)
                        for (int count = 0; count < objectSize; count++)
                             IInfoObject obj = (IInfoObject) iObjects.get(count);
                             // Specify the Destination parent Id to move the reports
                             obj.setParentID(44102);
                        oInfoStore.commit(iObjects);
                        System.out.println("Reports Moved Successfully");
                   else
                        System.out.println("Reports Not Available");
             catch (SDKException e) {
                 e.printStackTrace();
                 System.out.println("Error : " + e.getMessage());
    Thanks&Regards
    Damodar
    Edited by: Damodaram B on Nov 2, 2009 1:29 PM

    There's couple of things at issue here - you've not specified the proper interface (IProgramBase or IProgramBaseEx), and the program job server can't find the class in question (a deployment issue).
    You may want to open a support ticket with SAP.
    Sincerely,
    Ted Ueda

  • I have a program that requires Java 6.  I am running 10.8.2, How do I remove Java 7 to run this program?

    I have a program that requires Java 6.  I am running 10.8.2, How do I remove Java 7 to run this program?

    Try going to the Oracle site - they did have a page showing how to remove Java 7 using the terminal program.
    I followed their instructions and it didn't work for me, but you may have better skills and luck than I.
    This was my starign point;
    http://www.java.com/en/download/help/mac_uninstall_java.xml
    Let us know if this works.

  • Java/lang/NoClassDefFoundError when trying to run my program in Eclipse

    I have a problem when using Eclipse. I can compile my classes in Eclipse without problems, but when I try to run the main class I get the following error message:
    Error occurred during initialization of VM
    java/lang/NoClassDefFoundError: java/lang/Object
    I have the same classpath setup when compiling and running the program. I am using JDK 1.3.1 and also have no problem running the program using javaw from a command prompt.
    Please answer if you have encountered this problem or have any idea what the problem might be.

    I start Eclipse using the exe file eclipse.exe with no special arguments.
    I use a JRE installed in e:\jdk1.3.1_01 so on the JRE page in the launch dialog box I have added a JRE with e:\jdk1.3.1_01\jre as the JRE home directory. This means that the JRE system library contain e:\jdk1.3.1_01\jre\lib\rt.jar. On the classpath page this JAR file is also listed as well as some other JAR files I use in my project.

  • Why i get error msg when i run my program? (java.lang.NoClassDefFoundError)

    i have compile and run my program. First time the program can run. But after that when i run, come out error messege as below:
    java.lang.NoClassDefFoundError: FormPoster (wrong name: search/FormPoster)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    Exception in thread "main"
    what can i do? thank very much

    Hello,
    i have compile and run my program. First time theprogram can run.
    But after that when i run, come out error messegeas below:
    java.lang.NoClassDefFoundError: FormPoster (wrongname: search/FormPoster)
    Check your FormPoster class: the classname has to be
    the same as
    the file name and the class should be stored in its
    correct directory
    (the sub directory structure should reflect the
    package name).
    kind regards,
    JosYou should also check your clsspath if you are using packages.

  • How to run native program with Java program?

    Hello
    I've got following problem. I'd like to write file browser which would work for Linux and
    Windows. Most of this program would be independent of the system but running programs not. How to run Linux program from Java program (or applet) and how to do it in Windows?.
    Cheers

    Try this:
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("ls -l");
    InputStream stream = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stream);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null) .....
    "if the program you launch produces output or expects input, ensure that you process the input and output streams" (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)

  • I am getting that I need Java SE 6 runtime to run a program.  Can't find that.

    I am getting that I need Java SE 6 runtime to run a program. Can't find that.

    Java for Mac OS X 10.6 Update 17

Maybe you are looking for

  • HT201257 AHT - Blank screen with cursor, then gray screen, then shutoff

    I have a mid-2009 MBP 13" with a mid-2010 motherboard (courtesy of warranty repair), and am running OS X Mavericks. When I attempt to use my original Applications Install DVD, I have the above issue. Attempting to install additional software in OS X

  • JMicron + x58 Platinum + windows 7 64 bit = no go

    Hi all, I have an MSI x58 platinum running bios 3.7.  (ive also got a core i7 930 (3 x 2 GIG ram)) My issue is Ive just rebuilt it and i have just acquired 2 x 36GIG 10000RPM Raptors. Ive done as per the manual said and stuck them on SATA 7/8 made a

  • How to make a jiggly/bouncy camera

    Hello! i am 15 years old and i am already starting for a "portofolio" (not sure how to say it in english) for my school i want to go next 2 years, i am enjoying adobe products like photoshop and after effects, i am right now working on a "kinetic typ

  • 11.2.0.2 to 11.2.0.3

    Version: 11.2 Platform : Solaris x86 (64-Bit) I want to upgrade my 11.2.0.2.0 DB to 11.2.0.3.0. I realise that , starting from Sep 2010 release of 11.2.0.2, patchset comes in a single Installable. This is very usefuly when we do fresh Installation. B

  • How to use Structure In TableView

    Helo BSP Gurus, In BAPI_PO_GETDETAIL, upon giving the PO number it outputs the Header and Item Data. Item data is a Table so I can display n BSP using tableview. But header falls under import parameter and being a Structure, How shld I display n BSP