Invoking command prompt & executing a java class from one more java class

Hi,
I have a problem with my application. I need to develop an editor which compiles and interpretes java programmes. I am develoopping it in Java (Swing and pure Java). I have no problem in compiling a java programme from my editor. But while execuing if any body writes a programme which has console input the system hangs. I am using Runtime.exec() method to call command prompt of Win'2000. My editor is working fine for the programmes written without console input in my editor. I want the same type of input acceptance as JCreator / Vim editors accept.
How can i achieve this? Please give me some source code help for my requirement.

When you create a Process object from executing a command you can grab it's input and output streams. Using these, and a text area, you can create a "virtual terminal" for your user to work with their console programs. The rest is just details :)

Similar Messages

  • How to call a method in IMPL class from one context node

    Hi, I´ve been only study the posibility to access a method in the IMPL class  from one context node class...CN## without using events, is there a way to call it ??? I don´t have it as requierement just learning thanks !.

    Hi,
    Try this by following this you can get the custom controller instacne in the view context nodes, for your requirement you can keep the view implementation class instance instead of cuco..
    To get the custom controller instance in Context node getter/setter method:
    1. Declare Cuco instance reference variable in ctxt class..
    2. Set this cuco ref. in the Create context node method of ctxt class:
    try.
    gr_cucoadminh ?= owner->get_custom_controller( 'ICCMP_BTSHEAD/cucoadminh' ). "#EC NOTEXT
    catch cx_root.
    endtry.
    you can avoid this step as this is not needed in case of view isntance
    3. Assign this instance to the respective context node Create method using:
    BTStatusH->gr_cuco ?= gr_cucoadminh.  " here assign the view implementation ref. " me" instead of gr_cucoadminh
    Here gr_cuco is the ref. variable of custom controller in the respective context node for eg. BtstatusH
    Sample implementation of this can be found in
    ICCMP_BTSHEAD/BTSHeader ->context node BTACTIVITYH-> attr ->GR_CUCO(instance of cuco)
    Cheers,
    Sumit Mittal

  • Executing a Java Program from within a Java Program

    I need to execute the following Java Program from withing another Java Program. The office toolbar command line is
    D:\WINDOWS\system32\java.exe -cp E:\Development\Eclipse\UpdateServer\Classes -server -showversion UpdateServer
    I can find no combination of ProcessBuilder commands, including those that include "Cmd.exe /c" that will make this program run from within another Java Program. All the examples I can find only show how to run Windows *.exe programs. I keep getting error 123 from ProcessBuilder.start(), but I can find no documentation for error 123.

    Assuming your code didn't get mangled by the forum
    (it's missing one "), it may be that your "-cp
    E:\\Develop.." argument is getting quoted as it has a
    space in it; try passing "-cp" and "E:\\Develop..."
    as two arguments.That worked; specifically the following tested OK:
    ProcessBuilder pb = new ProcessBuilder("D:\\WINDOWS\\System32\\Java.exe", "-cp", "E:\\Development\\Eclipse\\UpdateServer\\Classes\\", "-server", "-showversion", "UpdateServer" );
    pb.directory(new File("E:\\Development\\Eclipse\\UpdateServer\\Classes\\"));
    try{
         Process p = pb.start();
         InputStream is = p.getErrorStream();
         InputStreamReader isr = new InputStreamReader(is);
         BufferedReader br = new BufferedReader(isr);
         String line;
         while ((line = br.readLine()) != null)
              System.out.println(line);
         p.waitFor();
    }catch(IOException ioe){
    I was sure I tried that exact same code before, and it did not work, but now it does, at least at the top level (when it is in main of a test program). I will have to wait to try it until later when it is buried deep in a subroutine.

  • How to execute a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say the Perl program that I want to execute is 'abc'. Now, 'abc' requires some input that I want to give it from within the Java program. How do I do it?
    And finally, how do I execute that Perl program from within the Java program.
    If I execute the Perl program alone then I do it in the following way -
    perl abc inp1 inp2 inp3
    where inp1, inp2, inp3 are inputs to the Perl program. I will not be able to change or modify the coding of the Perl program - 'abc' as I do not have access to its code. Its a kind of an application whose usual method of execution is in the above shown way. So, how do I execute 'abc' from within a Java program.

    what part of don't crosspost, don't you understand?
    http://forum.java.sun.com/thread.jsp?forum=4&thread=427193

  • Executing a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say that the Perl program that I want to execute is 'abc'.'abc' requires some input that I want to give from within the java program. How do I do that? Then I want to execute the Perl program from within the Java prog. How do I do it?

    don't crosspost.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=427211&tstart=0&trange=100

  • Is it possible to compile & run other java files from one file

    hi friends,
    i need to run 2,3 java sourse files(first.java,second.java etc) from one file.i tried the Runtime.getRunTime().exec( cmd) but here cmd must be a executable file
    what is need is to compile and run the files (first.java,second.java) from one other source file
    pls. help me in this matter,
    with warm regards,
    Vishal

    Sure:public class Test {
       public static void main(String[] args) {
          try {
             Runtime r = Runtime.getRuntime();
             r.exec("javac Test2.java");
          } catch (Exception e) {
    public class Test2 {
       public static void main(String[] args) {
          System.out.println("Hello World!");
    }Note that Test and Test2 are in two seperate files.

  • How to run java programs from a master java program?

    Hello,
    I have several java programs which run from the command prompt. I am seeking help with code for starting java programs from within a java program. For example, a program called master.java works something like this:
    import java.*;
    create connection pool
    create variables and result sets
    start/run slave1.java (var1, var2);
    start/run slave2.java (var3, var4, var5);
    start/run slave3.java (var1, var4);
    end of program master.java
    Each of the slave.java programs will run for up to an hour. I do not want the master.java program to pause for each slave program to stop. Instead, the master program will keep running and multiple slave programs will be running simultaneously with the master program. When a slave program starts, it is on its own. Also, if possible, I would like to have each of these slave.java programs open in a new separate command window, so I can observe each slave program running in separate windows.
    Any suggestions for code or helpful documentation are greatly appreciated.
    Thank you,
    Logan

    Thank you all.
    At the bottom of master.java I have successfully started a batch file with these lines:
    String jcmd = "cmd.exe /c start c:/data/simulations/MsgViewCount2.bat";
    Process proc = Runtime.getRuntime().exec(jcmd);
    But I still cannot get a java program to start. Here is one variation I have tried:
    String [] cmdArray = new String[2];
    cmdArray[0] = "java";
    cmdArray[1] = "slave1";
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec(cmdArray);
    This compiles, and no errors occur, but nothing happens.
    Regarding this comment:
    Why Runtime.exec? Either make the slaves Runnable or
    just call their main() methods.
    Oh, I see. Sepearate output. :PNone of the slave.java programs have any output.
    Thanks again.

  • Compiling java code from a running java application

    How does compiling of java code from a running java application work?
    I found a class: com.sun.tools.apt.main.JavaCompiler
    but cannot find any documentation of how this class works.

    How does compiling of java code from a running java
    application work?Probably most reliably using Runtime.exec().
    I found a class:
    com.sun.tools.apt.main.JavaCompiler
    but cannot find any documentation of how this class
    works.For a purpose. You are not supposed to use this class. With the next JRE release or implementation, it might not exist anymore - it's not part of the standard API.

  • How to extend JAXB genrated classes from other application specifc classes

    Hi,
    I would like to know, is there a way to extend JAXB genrated classes from my application specific classes?
    Thanks!

    extend JAXB genrated classes from my application specific classes
    In JAXB 2.0 a Java class may be mapped to an XML document or an XML Schema with annotations in the javax.xml.bind.annotation package.

  • Transforming java Code from one Flavor to another

    How do you transform java code from one flavor to another.
    Please help
    Juan

    what's that - java flavor ?

  • Initialize/set a base class from a another base class instance

    Hi,
    How can I initialize/set a base class from a another base class instance? I do not want to do a copy of it.
    It would look something like:
    class A {...}
    class B extends A
        B(A a)
            // super = a;
        setA(A a)
            // super = a;
    }Thank you.

    erikku wrote:
    Thanks Winton. It is what I did first but A has lots of methods and if methods are later added to A, I will have to edit B again. For those two reasons, I wanted to use inheritance. The part I was not sure with was the way to initialize B's base (A).You pays your money and you takes your choice. One way (this way) you have to provide forwarders; the other way (inheritance) you have to provide constructors (and if A has a lot of em, you may be writing quite a few).
    Ask yourself this question: is every B also an A? No exceptions. Ever.
    If the answer is 'yes', then inheritance is probably the best way to go.
    However, if there is even the remotest chance that an instance of B should not exhibit 100% of the behaviour of A, now or in the future, then the wrapper style is probably what you want.
    Another great advantage of the wrapper style is that methods can be added to A without affecting the API for B (unless you want to).
    Winston
    PS: If your Class A has a constructor or constructors that take a pile of parameters, you might also want to look at the Builder pattern. However, that's not really what we're talking about here, and it should probably be implemented on A anyway.

  • Invoking command prompt from Java

    public class NewClass2 {
    public static void main(String[] args) {
    Runtime p = Runtime.getRuntime();
    p.exec("cmd");
    I would like to invoke dos prompt from my java application. The above code is not working. What could be the problem? I am using Windows XP m/c with netbeans.

    jjegan wrote:
    public class NewClass2 {
    public static void main(String[] args) {
    Runtime p = Runtime.getRuntime();
    p.exec("cmd");
    I would like to invoke dos prompt from my java application. The above code is not working. What could be the problem? I am using Windows XP m/c with netbeans.You didn't give it hands and feet, i.e. you can't expect the cmd.exe process to fire up a terminal for its input and output; you have to do that yourself. Read all about the Input- and OutputStreams of those sub-processes in the API documentation of the Processs class.
    kind regards,
    Jos

  • How can I execute a  .bat  file from inside a java application

    I have a .bat file which contains an executable file(.exe) and some input and output file names. What commands can I use to execute this bat file from my java application.

    After raeding tkleisas' reply; i am trying to invoke another application (which can be invoked from the command line) by using a batch file and trying Runtime.exec for executing a batch file.
    My current code is:
    Runtime runtime = Runtime.getRuntime();
    Process trialProcess;
    trialProcess = runtime.exec("cmd.exe /C start C:\\guns.bat /B");
    And my guns.bat looks like:
    cd C:\CALPUFF
    echo trial
    start calpuff.exe CALPUFF.INP
    This is not working for me and i get the following in the error stream of the trialProcess:
    Error :
    The system cannot execute the specified program.
    Process finished with exit code 1
    Has anyone come across something like this and know what's wrong with this one??
    thnx

  • How do you run another Java file from a master Java file?

    We're making a game in Java at school, and we need to know how we can run a Java file from another one - like inside the master Java file, we need to have a command to run game.java (something like that). Thanks!

    We're making a game in Java at school, and we need to know how we can run a Java file from another one - like inside the master Java file, we need to have a command to run game.java (something like that). Thanks!One doesn't "run a Java file", and there's no conventional definition of "master Java file". If you want to call the main() method of another class, just make sure the class is in your classpath and call the method. If you want to start up a separate JVM with that class as a process, use Runtime.exec() or similar method.
    ~

  • URLClassLoader loading class from jarB, which uses classes from jarC

    Hi, here's my problem:
    I have a classA in executable jarA.
    This uses URLClassLoader to load classB from jarB. So far so good.
    But classB uses classC, which lives in jarC. jarC is specified in the Class-Path of the manifest in jarB. But classB gets a ClassNotFound exception when it tries to use classC.
    The situation I want to achieve looks like this (sorry for the bad art; it's almost impossible to make it look better because sun strips out extra spaces):
    jarA:
    classA-----> URLClassLoader(jarB).loadClass(classB)
    jarB:
    Class-Path jarC
    classB------> new classC
    jarC:
    classC
    My expectation was that URLClassLoader would automatically be used to load all the classes that classB uses, and that it would extend its classpath by the classpath specified in the manifest of jarB, just like the default classloader does. Anyone know what I'm doing wrong?
    When I do the following, i.e. use only the default classloader, everything works fine. Unfortunately I won't know where jarB is until runtime, so I can't actually do this:
    jarA:
    Class-Path jarC
    classA-----> new classB
    jarB:
    Class-Path jarC
    classB------> new classC
    jarC:
    classC
    thanks alot
    j

    Actually, there is definitely a way to make this work. A plugin engine has to handle this in order for plugins loaded by separate loaders to be able to share class instances with one another (dependency). My engine does static runtime plugin dependency resolution, which means it parsers every plugin's config file, then after all plugins are in the "registry" it goes back and resolves all dependencies. How it does this is that each PluginClassLoader keeps a list of "dependent" classloaders. So, if the engine finds plugin A, B, and C, and B depends on C (declares this in its config file), the engine creates 3 class loaders (custom loader called PluginClassLoader), one for each plugin. This is done so that the plugin can be unloaded or reloaded at runtime without having to shut the application down. Now, since B depends on C, when plugin B code requests a class found in C, the JVM first asks B's loader to find the class. The "normal" delegation model of Java is for B's loader to first look in the parent hierarchy, then in its own classpath. The problem with this approach is that in order to support reloadable and unloadable plugins, you do NOT want your plugin .jar file at any location within the main application classpath. The plugin .jar file should be able to be at any URL location outside of any other classpath, even perhaps at another web site.
    So, the JVM asks B to find the class in C. But B's loader isn't able to find it because it is not in B's classpath. The trick is to do one of a couple things. First, remember that each loader keeps a list of dependent loaders. Second, in order to avoid any tie-in to the main classpath, we break the normal classloader delegation model by overriding the loadClass() method. In here we want to first check our local cache of loaded classes. The built-in method findLoadedClass() handles this for us. If that doesn't return a Class, then we want to look in our own classpath. In this case, we only want to look for any classes in B's plugin .jar file. C's class of course wont be found here. So the next step is to delegate to our "dependent" list of loaders. Aha, you say? This is the trick (credit goes to the Eclipse IDE team where a few members taught me this and was able to help me solve my very same problem). By delegating to a dependent loader, B's loader effectively asks C's loader to find C's class. The same thing happens, only this time it is now C's loader doing the work. The very first time the calls is made, no classes are loaded yet, so the finding of the C class in the local cache of C's loader wont yet work. The next step though, looking in C's classpath (C's .jar file) WILL find the class. It is loaded, put in C's loader cache and the Class is returned. Now, at this point B now has a Class from C's classpath that it can use.
    Now, my first foray into this made me think that if B asks C to find it, and C finds it and loads the bytecode, doesn't B's loader also need the bytecode in order to properly "see" the C class. Apparently, this is not needed. I am guessing the JVM keeps a repository of bytecode, so that so long as you have the C ref (location in the JVM's memory where C's bytecode is), you don't need to re-load the bytecode of C into B's loader. Thus, B's loader now can "see" the C class without actually having to have loaded the bytecode of C. Now, B's code can typecast C, use it, etc. Beautiful aint it?
    Let me know if you have any further questions.

Maybe you are looking for

  • Need to add new row in my table

    Hi all, 1. i am developing new OAF page in which i have call stored procedure in my AM but when add code for create additional row only single row is creating.when i click for another row nonew is created. please help.. this is the code i have used i

  • Sound no longer works after upgrade to Windows 8.1

    System: Operating System Windows 8.1 64-bit CPU Intel Core i5 3330 @ 3.00GHz 23 °C Ivy Bridge 22nm Technology RAM 8.00GB Dual-Channel DDR3 (11-11-11-28) Motherboard LENOVO MAHOBAY (SOCKET 0) 18 °C Audio ASUS Xonar DGX Audio Device I sucessfully upgra

  • Asset report Problem?

    Hi, We have to make an Asset report but we are unable to get some fields: Acquisition Cost: Original Asset Addition in this year Retirement in this year Transfer in this year Current Asset cost Dep. Cost Original Asset Addition in this year Retiremen

  • Profit center - actual data and plan data question -?

    Hi Gurus Please clear my doubts in profit cneter accounting. 1) what is PLAN data  -? (What is planning in a bigger picture) why do we need plan data -? 2)ACTAUL data will be posted in the profit center from other SAP moduldes. So with out PLAN data 

  • F110-Text field requirement

    Hello Experts, While making payment to the vendor through F110, we need text field to enter text for our reference but standard SAP has not provided text filed for the payment documents through Automatic payment run. Please let us know through ABAP c