How to run java source files from other java files??

hello all,
i need to run 3 to 4 .java files (first.java,second.java,third.java) from one file.
i tried the
Runtime.getRuntime().exec(cmd); but here cmd must be an exe file.
NOTE THAT i need to run the first.java file ,second.java file each time to generate their .class files(ie I NEED TO COMPILE THEM ALL TIMES AND THEN RUN THEM)
PLZ. help me if this can be done,
warm regards,
Vishal.

One way to do this is to put all your commands into a batch file (this is Windows?) try unix shell otherwise. Anyway here's an example .bat file called cmplrun.bat:
@echo off
javac -classpath . TestCase*.java
java -cp . TestCase01
java -cp . TestCase02
java -cp . TestCase03Then the Java pgm can look like this:
import java.io.*;
public class RunProcess {
  public static void main(String[] arg) {
    try {
      Process myProcess;
      myProcess = Runtime.getRuntime().exec("cmd /c cmplrun");
      String s = null;
      DataInputStream in = new DataInputStream(
                           new BufferedInputStream(
                               myProcess.getInputStream()));
      while ((s = in.readLine()) != null) {
        System.out.println(s);
      System.exit(0);
    catch (IOException e) {
      System.out.println("Exception: "+ e);
      System.exit(-1);
}Just one way to do this, all caveats apply and HTH;
~Bill

Similar Messages

  • How to run a openssl command from a java program

    Hi All
    Please suggest on how to run a openssl command from a java program.
    I am using this
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
    This is suppose to take test.der as input and create result.pem.
    There are no errors but the file result.pem isnt created.
    Thanks in Advance

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • How to run a cygwin.bat from a java program?

    Can you please let me know how to run a cygwin.bat file from a java program and to give commands through java program. I have a program to run .exe files, but when I do the same for the cygwin.bat it doesnt work. In task mgr a BASH and a cmd.exe is running. Please help me on this & bit urgent. Thanks in advance!

    Can you please let me know how to run a cygwin.bat
    file from a java program and to give commands through
    java program. I have a program to run .exe files, but
    when I do the same for the cygwin.bat it doesnt work.Of course not. .bat files are no native executables. You need to open a shell first, like "cmd /c cygwin.bat ..."
    & bit urgent. Thanks in advance!If I had read this earlier I wouldn't have replied. Why exactly is your time worth more than anybody else's?

  • How to hide the source code from the .class file

    Hi,
    By some jad tool we can recompile the .class files and get the java file corresponding to it. How to protect it?
    Anyone please help me..
    Thanks & Regards,
    N.Ravasankar

    An obfuscator can for example rename classes, variables to meaningless names, like one-letter names. And it can make some bytecode that is hard to decompile or just makes the code less readable when decompiled. Some obfuscators might even be able to do something to the code that makes decompilers not work or incorrect decompile code.

  • Problem creating a PDF file from other PDF files

    Normally, the process works, but sometimes produces the following error (in Spanish):
    El documento no se pudo archivar. Problema al leer el documento (110)
    Does anyone know the origin of the error? We have reviewed the security of files and is correct
    Thanks

    I am not sure, but it may be a font mismatch between the files. Fonts is one of the issues that often crops up as a problem when combining PDFs.

  • How to compile and run a .java file from another java program

    hello,
    can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?

    Well a smarter way of implementing this is by using a solution provided by Java Itself.
    If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
    http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
    How do i do that ??
    Check out the below articles which would help you of how to do that
    http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
    http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
    http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
    Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
    Hope that might help :)
    REGARDS,
    RaHuL

  • How to run exe file from inside java

    I wan to run an exe file from inside java code. How can I do it?
    Thanks

    Hi Oakam
    This is very simple. Just go through the given code below
    in place of FILEANDPATHNAME just give the exe's path and name
    Note :- adding ".exe " is not necessary
    public class exep
    public static void main(String args[])
    Runtime r = Runtime.getRuntime();
    Process p = null;
    try{
    p = r.exec("FILEANDPATHNAME");
    catch(Exception e)
    Give ur feedback
    Thanx
    Ottran

  • How to source .Xdefaults' color settings from other config files?

    I'd like to reuse the colors I've setup in my .Xdefaults in other config files, I'm not sure if I could somehow source these from other scripts, or if I should centralize them another way...
    Any pointers ?
    cheers

    Knute wrote:
    I don't have a clue but have you checked the archwiki?
    http://wiki.archlinux.org/index.php/Xdefaults
    sure...
    Knute wrote:Though, in partial answer to your question, I would suggest that perhaps, those programs that use the terminal color notations could be affected by *colorX (where X is a number between 0 and 15).
    Unfortunately that doesn't seem to be working...
    Knute wrote:The other option, is to maybe set theose colors up in a different script that just exports the names, and then use those variables?
    Gues that's what I'll do...

  • How can I run Runtime.exec command in Java To invoke several other javas?

    Dear Friends:
    I met a problem when I want to use a Java program to run other java processes by Runtime.exec command,
    How can I run Runtime.exec command in Java To invoke several other java processes??
    see code below,
    I want to use HelloHappyCall to call both HappyHoliday.java and HellowWorld.java,
    [1]. main program,
    package abc;
    import java.util.*;
    import java.io.*;
    class HelloHappyCall
         public static void main(String[] args){
              try
                   Runtime.getRuntime().exec("java  -version");
                   Runtime.getRuntime().exec("cmd /c java  HelloWorld "); // here start will create a new process..
                   System.out.println("Never mind abt the bach file execution...");
              catch(Exception ex)
                   System.out.println("Exception occured: " + ex);
    } [2]. sub 1 program
    package abc;
    import java.util.*;
    import java.io.*;
    class HelloWorld
         public static void main(String[] args){
         System.out.println("Hellow World");
    } [3]. Sub 2 program:
    package abc;
    import java.util.*;
    import java.io.*;
    class HappyHoliday
         public static void main(String[] args){
         System.out.println("Happy Holiday!!");
    } When I run, I got following:
    Never mind abt the bach file execution...
    I cannot see both Java version and Hellow World print, what is wrong??
    I use eclipse3.2
    Thanks a lot..

    sunnymanman wrote:
    Thanks,
    But How can I see both programs printout
    "Happy Holiday"
    and
    "Hello World"
    ??First of all, you're not even calling the Happy Holiday one. If you want it to do something, you have to invoke it.
    And by the way, in your comments, you mention that in one case, a new process is created. Actually, new processes are created each time you call Runtime.exec.
    Anyway, if you want the output from the processes, you read it using getInputStream from the Process class. In fact, you really should read that stream anyway (read that URL I sent you to find out why).
    If you want to print that output to the screen, then do so as you'd print anything to the screen.
    in notepad HelloWorld.java, I can see it is opened,
    but in Java, not.I have no idea what you're saying here. It's not relevant whether a source code file is opened in Notepad, when running a program.

  • How to create windows executable file from a java file. Please help.

    Hi,
    For my project I developed the codes in Java. It is working well with java run time environment. But without that I can not run it. I need to create a exe file (windows executable file) from the java source code. If you have any idea please share it with me.
    Even if you know it very lightly, please help with what you know. That would be a big help for me.
    Thank you very much.

    Does anybody know how to read a manual?
    Matt Richardson
    Certified LabVIEW Developer
    MSR Consulting, LLC

  • How to run unix shell script from java web applet

    hi all
    i have created one java applet. my apache web server is on unix server.
    i have created one shell script in same directory where my .class and .htm files reside...
    how to run this shell script from applet? it should search this .sh file on server and not on the client browser machine...
    thanks in advance

    I suppose you could make the shell script into a CGI, configure the server to execute CGIs, and then make the applet open the URL of that CGI.

  • How to call a .jar file from a java bean?

    any body knows how to call a .jar file from a java bean?

    Crosspost!
    http://forum.java.sun.com/thread.jspa?messageID=4349619

  • How to backup files from other user logged in as administrator

    RE: How to backup files from other user logged in as administrator AND/OR how to repair drive with "Invalid catalog PEOF"
    Hello,
    My MacBook Pro computer’s hard drive is not booting.
    I booted with the base operating system and ran Disk utilities and I got the following messages:
        Invalid catalog PEOF
        The volume could not be verified completely.
        This disk needs to be repaired.
        Disk utility can’t repair this disk. Backup as many files as possible, reformat the disk,
        and restore your backed-up files.
    The problem is that I have a couple of USERS set up on this computer, and it won’t let me backup the files of the second user.  The folders are locked and I can’t access them, even though I am logged in as the administrator.
    I made a boot disk on my other computer ( a MacPro Early 2008 ) desktop computer with the DiskWarrior 4.4 updater,
    but it won’t boot on my MacBook Pro.
    How can I backup these user files so that I can copy them back once I fix the drive?
    or better yet,  How can I repair the Invalid catalog PEOF on this drive?
    Thank you in advance for your time! 
    Bill
    THIS IS THE COMPUTER
    ================
    17” MacBook Pro 2.8GHZ 4GB Ram (purchased in 2009).
    Model: A1297
    Running Mac OSX 10.9.5

    Try using Disk Utility/Restore to copy the backup to a new location. Please note that this will reformat the destination partition which will erase all data.
    Do a backup. Boot to the Recovery Volume (command - R on a restart or hold down the option/alt key during a restart and select Recovery Volume). Run Disk Utility Verify/Repair and Repair Permissions until you get no errors.  Reformat the drive using Disk Utility/Erase Mac OS Extended (Journaled), then click the Option button and select GUID. Then re-install the OS.
    OS X Recovery
    OS X Recovery (2)
    When you reboot, use Setup Assistant to restore your data.

  • How to make a jar file from a java file?

    how to make a jar file from a java file, is there any one tht can help me thank you;

    You can study this.
    http://java.sun.com/docs/books/tutorial/jar/basics/index.html

  • How can I execute a batch file from my java program

    Hi,
    Can someone help me or direct me to a link,
    How can I execute a DOS batch file from my java program?
    Thanks

    You will need to grab a handle to the process's
    outputstream so u can see its output.The OP didn't mention any output from any batch file;
    nor any input for that
    matter,so lets not complicate matters here for now
    ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
    I'm sure it wasn't intentional that your post appeared to be bristling with attitude.

Maybe you are looking for

  • ABAP Objects with Workflows / Classes and Instances

    Hello, I am currently designing a workflow using an ABAP-Objects. So far I have been been able to get my Workflow to run with my class, but I have a couple of problems: - I am using the Function 'SAP_WAPI_START_WORKFLOW' to start other subflows, whic

  • Auto collapse a mobile accordion menu when clicking links to anchors on the same page

    I'm building a mobile site, with the accordion widget containing the a menu widget, pinned to the top (i added custom css to pin it to the top). its a single page site, so all the links are to anchors in the same page. how can I make the accordion cl

  • Microsoft-Windows-Windows Remote Management Error ID 142

    In my Windows Server 2008 R2 OS in the Event Viewer there is an error pertains as Microsoft-Windows-Windows Remote Management Error ID 142 states-(WSMan operation CreateShell failed, error code 2150858999).What is this error? And What is the remedy f

  • Pasting Ken Burns  Into Clips Moves clip

    This has only happened a few times.   To save time, I paste the ken burns attributes into multiple selected clips.  I use the paste attributes command.  At times when I to that the clip itself is moved out of the visible movie frame.   I have only no

  • Visitor unabe to see the page content in WPC

    Hi Experts, I have created a website using  WPC, and I created a role and assigned the site to that role using external connector property.  I assigned that role to me and other users ( Authors, Visitors, Editors) . Problem is , I am able to see all