Execute a java program from an another program

Like we can compile a code from wihin a java file by using the following :
Tool javac = ToolProvider.getSystemJavaCompiler();
Similarly,can we execute i.e. run a java program from within a java file i.e. running d java command from within the java file ??If yes then please tell me how??

suppose on the Unix box or from a Unix script ( korn, perl, bourne, bash) you can run the following java program
java ${JAVA_OPTS} -jar ${GMR_APPS_DIR}/risk.jar -I -c ${COB} -r ${BATCH} -o ${XML_DIR}
in java you can do the following :
Runtime rt = Runtime.getRuntime();
          try {
               Process process = rt.exec("java ${JAVA_OPTS} -jar ${GMR_APPS_DIR}/risk.jar -I -c ${COB} -r ${BATCH} -o ${XML_DIR}
// OR
               Process process = rt.exec("/export/apps/Tools/apache-tomcat-5.5.17/bin/startup.sh");
               // process.destroy(); if you want to kill the process
               process.waitFor();
               int RC = process.exitValue();      
               System.out.println(returnOutput(process.getErrorStream()));
               System.out.println(returnOutput(process.getInputStream()));
          } catch (Exception ex) {
               ex.printStackTrace();
empty the output stream from the script
private String returnOutput(InputStream is) throws Exception {
               String s;
               StringBuffer strBuff = new StringBuffer();
               BufferedReader br = new BufferedReader(new InputStreamReader(is));
               while ((s = br.readLine()) != null) {
                    strBuff.append(s);
               return strBuff.toString();
          }You need to relace the ${} by the appropriate values.
Regards,
Alan Mehio
London, UK
Edited by: alan_mehio on Jan 16, 2008 4:21 PM

Similar Messages

  • FM to pass one variant to another called program from a calling program

    Hi Gurus,
    Please let me know the name of the function module to pass one variant to another called program from a calling program without displaying the selection screen of the called program.

    you can use fm rs_variant_fetch to retrieve the variant info.
    Check the abap help on the statement submit to get info on how to call a program with variables, or a variant
    Kind regards, Rob Dielemans

  • Calling another program from the current program

    Hi all,
    In our requirement we are calling another program from our current program .
    In the current program( from which we are calling ) we are giving file name in the selection screen
    and when we run the current program we are successfully going to other program but our main requirement is to higlight the file name which we had given earlier .
    Note :  The called program doesnt have any selection screen.

    HI
    use EXPORT and IMPORT key words for passing data from one program to another program.
    as the called program is available in the same session you can use above key words which means you are accessing ABAP MEMORY.
    You can also use SET and GET key words which means SAP memory
    take F1 help there are examples tooo and detailes explanation abou the same
    Regards
    Ramchander Rao.K
    Edited by: Ramchander Krishnamraju on Dec 24, 2008 7:05 AM

  • Calling a Java Subpackage from a C program.... fails

    I am having alittle bit of trouble calling a java subpackage from my C program. I can call a package ok but not a subpackage.
    My directory path is c:\com\phoenix_systems_inc
    My CLASSPATH=.;c:\com;
    In the c:\com\phoenix_systems_inc directory is my FundsgClient.class
    The fundsgClient.java has a package declaration of
    package com.phoenix_systems_inc;
    within the fundsgClient.java is class:
         public synchronized static String setValue (String str) {
         String a = "You passed: " + str;
         return a;
    ======================================
    in my C program I have
    options[0].optionString = "-Djava.class.path=c:\\com\\";
    cls = env->FindClass("/phoenix_systems_inc/com.phoenix_systems_inc.FundsgClient");
    I think that I am over declaring the path in FindClass.

    nope;; that is what I had initially;
    My CLASSPATH is CLASSPATH=.;c:\com;
    ==================================C program code
    memset (&vm_args, 0, sizeof(vm_args));
    vm_args.version=JNI_VERSION_1_2;
    vm_args.options = options;
    vm_args.nOptions = 1;
    options[0].optionString = "-Djava.class.path=c:\\com";
    vm_args.ignoreUnrecognized = TRUE;
    res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
    if (res < 0)
    fprintf(stderr, "Can't create Java VM\n");
         return 0;
    cls = env->FindClass("com/phoenix_systems_inc/FundsgClient");
    ===== is the java class code ==========
    package com.phoenix_systems_inc;
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;
    import gnu.cajo.invoke.Remote;
    import gnu.cajo.utils.extra.Xfile;
    * Fundsg RMI Client
    * @author agesite
    * @version 1.0
    public class FundsgClient {
    static {
    PropertyConfigurator.configure("FundsLog.properties");
    // Log4j logger
         private static Logger log = Logger.getLogger("PhoenixClient");
    // Get RMI Server Hostname
    private static final String host = PhoenixClientProperties.getInstance().
    getProperty("PhoenixRMIServer");
    private static String port = "1198";
         * request
         * @param requestStr Request String
         * @return String Response String
         * @throws Exception
         public synchronized static String request (String requestStr) throws Exception {
              // Serialized object
              RequestObject requestObj = new RequestObject();
              requestObj.setRequest(requestStr);
              if (log.isDebugEnabled()) {
                   log.debug("Client Request: " + requestStr);
              System.out.println("//" + host + ":" + port + "/fundsgServer");
              Object object = Remote.getItem("//" + host + ":" + port + "/fundsgServer");
              String response = (String) Remote.invoke(object, "nativeFundsg", requestObj.getRequest());
              if (log.isDebugEnabled()) {
                   log.debug("Server Response: " + response);
              return response;
         * xferFile
         * @param sourceFile
         * @param destFile
         * @throws Exception
         public synchronized static void xferFile (String sourceFile, String destFile) throws Exception {
              try {           
                   Object xf = Remote.getItem("//" + host + ":" + port + "/xfileFunds");
                   // remoteInvoke = true means transfer can be performed from
    // server to client and vice versa
    Xfile.remoteInvoke = true;
                   Xfile.fetch(xf, sourceFile, destFile);
              } catch (Exception e) {
                   if (log.isDebugEnabled()) {
                        log.debug("Xfile.fetch exception: " + e);
         public synchronized static String setValue (String str) {
         String a = "You passed: " + str;
         return a;
    }

  • Spawning child program from parent concurrent program.

    Hi All,
    I am trying to spawn multiple child programs from Parent concurrent program, Parent concurrent program is having execution method as HOST.
    Here is how I designed it.
    1. Parent Concurrent program (Parent Conc program with execution method as HOST).
    2. Host file is abc.prog calls PLSQL package xyz.main.
    3. xyz.main has logic to launch multiple child programs - (Child Conc program with execution method as PLSQL stored proc) using fnd_request.submit_request utility.
    All the child programs are getting launched but are in INACTIVE/NOMANAGER state. Could you please let me know how to overcome this issue.
    Both Parent and child programs are added to standard concurrent manager. This issue is only coming when parent program as execution method as HOST if parent program execution method is PLSQL stored procedure then child programs are running fine..
    I also tired initializing apps in HOST file (abc.prog) before calling PLSQL package xyz.main.
    Thanks.
    Sham.

    hi,
    even i was facing the same issue. while submitting the child requests through fnd_request.submit_request i tried the following:
    FND_REQUEST.submit_request (
    application => 'Application Short Name',
    program => 'Program Executable Name',
    description => 'Program Description',
    start_time => NULL,
    sub_request => FALSE,
    argument1 => 'Input 1',
    argument2 => 'Input 2' );
    After this the Programs were submitted successfully.

  • Program  to list all include programs  from the  Sap program list

    My requirement is to display all include programs from the Sap program Table ( D010INC table and TADIR table), From
    here i have to get all include programs.Can anyone give the program code for this requirement

    well, it's your requirement and not ours, so why not try yourself first?

  • Executing a java application from c++ using jni

    hi,
    how do i execute a java application from c++ ?. it should behave similar to typing 'java abc.class' at the dos prompt.
    i've done up till recognizing the method id. GetStaticMethodID(). I tried using CallStaticVoidMethod() but didnt work. are there any other methods i should be using?

    Look at the source code to the "java" command that is included in the sources that come with the JDK. Since it is the exact code that is run when you type java at the command line, it should be close to what you want.

  • How can I call a java class from within my program?

    I was wondering if there's a platform independent way to call a java class from my program.

    Here's my scenario. I'm working on a platform independent, feature rich, object-oriented command prompt program. The way I'm designing it is that users can drop classes they write into my bin directory and gain access to the class through my program. For example, they drop a class named Network.class in the bin directory. They would type Network network at my command prompt and gain access to all the methods available in that class. They can then type system.echo network.ipaddress() at my prompt and get the system's ip address. I have it designed that there's a server running in the background and the clients connect to my port. Once connected the end-user can enter their user name and password and gain access to the system. When they type a command they actually call another java program which connects to my server using a seperate thread. They can then communicate back and forth. I have it set that everything has a process id and it's used to keep track of who called what program. Once the program is done it disconnects and closes. Rather than getting into the nitty gritty (I didn't want to get into heavy detail, I know how everything will work) I'm really interested in finding out how I can call a java program from my program. I don't want it to be part of the app in any way.

  • How do I start and suspend Java Application from say C++ program

    I want to start a Java application via C++ and on some condition i want to suspend the same program not terminate , but suspend

    Have you tried running the virtual machine from your C++ application ? You can start Java applications from your C++ application using JNI after starting the Virtual machine from within your C++ application. According to the Java documentation you can even now stop the virtual machine from within your C++ program.
    I haven't looked at the 'suspend' detail but I suppose it will not be a problem to call a method via JNI to set a flag to suspend a thread etc.
    There is a tutorial: 'Invoking the Java Virtual Machine' at the following URL: http://java.sun.com/docs/books/tutorial/native1.1/invoking/invo.html.
    This example seems to work only for version1.1 of the JDK. For JDK1.3, version 1.2, (I am not so sure whether I fully understand Sun's version numbers for Java yet) there is some updates on the JNI for starting the VM from C++. This article is called 'JNI Enhancements'. The URL for this article is:
    http://java.sun.com/j2se/1.3.0/docs/guide/jni/jni-12.html
    You have to set version to: JNI_VERSION_1_2
    There is only one problem. I get an error when calling JNI_CreateJavaVM from C++. I could not find any documentation that indicates how you can go about diagnosing what is causing the problem. Normally in Visual C++ you can just get the probable cause by inspecting GetLastError() or the function itself can return helpful diagnostic (error) codes.
    If you manage to start the VM correctly from within Visual C++ please let me know. My email address is [email protected]
    good luck
    Henko

  • Access java properties from C++/JNI program

    Hello all,
    Is it possible to access the Java properties of a JNI VM from a C++ program?
    If so, could the code or process be explained to me.
    I want to be able to identify a specific VM that is retrieved by the JNI_GetCreatedJavaVMs
    call. I set a user property when the VM was created, and would like to verify its value
    before calling AttachCurrentThread.
    Thanks in advance.
    Mark

    Are you saying that you set a system property (via System.setProperty() or -D)?
    If so, just use the JNI invocation API to call System.getProperty().
    Without error checking, that looks something like this:bool isMySystem( JNIEnv* env ) {
      const string PropertyName = "IsMySystem";
      jclass systemClass = env->FindClass( "java/lang/System" );
      jmethodID getPropertyMethod = env->GetStaticMethodID( systemClass, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;" );
      jstring propertyNameString = env->NewStringUTF( PropertyName.c_str() );
      jstring propertyString = env->CallStaticObjectMethod( systemClass, getPropertyMethod, propertyNameString );
      if ( propertyString == 0 ) {
        return false;
      const char* property = env->GetStringUTFChars( propertyString, 0 );
      boolean isMine = ! strcmp( property, "Yes" );
      env->ReleaseStringUTFChars( propertyString, property );
      return isMine;
    }Using Jace, http://jace.reyelts.com/jace (a free, open-source toolkit), this would look more like:bool isMySystem() {
      String property = System::getProperty( "IsMySystem" );
      return property.isNull() ? false : prop == "Yes";
    }In the end, Jace ends up making all of the exact same calls, but you can see how much easier it is to use.
    God bless,
    -Toby Reyelts

  • 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 :)

  • Error: ORA-03113 while executing complex java code from Oracle PL/SQL

    Hi,
    I am trying to execute a complex java code from Oracle PL/SQL. The classes were resolved successfully. But in the middle of execution, I am getting the following error:
    ERROR:
    ORA-03114: not connected to ORACLE
    begin
    ERROR at line 1:
    ORA-03113: end-of-file on communication channel
    Process ID: 13685
    Session ID: 21 Serial number: 20
    Is there a way to debug the Java classes loaded into oracle? Or is there any utility to find out why the connection was lost?
    Regards,
    Saravana

    Hi Saravana:
    You could use simply System.out.println(..) at your Java code and see the output at the .trc files generated for your Oracle session.
    Or better than this adding Java Util Logging messages at your code, to see how to use JUL API at the OJVM please see this blog post [Using JUL API inside the OJVM|http://marceloochoa.blogspot.com/2007/11/getting-logging-entering-exiting-and.html].
    Best regards, Marcelo.
    PD: ora-0600 generally are associated with RDBMS bugs, but these bugs can be bypassed by replacing the code which throws the exception by other with a workaround.

  • Do you want to allow the following program from Unknown Publisher - Program Name: CompMgmtLauncher.exe etc

    Dear All,
    I'm facing some issue in WINDOWS SERVER 2008 R2 on each windows settings its prompting for UAC  like on windows settings (Server Manager, Network Settings, Firewall Settings etc) and in Publisher "Unknown"
    is showing though its windows settings.
    ERROR: "Do you want to allow
    the following program from Unknown Publisher. . . . "
    Program Name: CompMgmtLauncher.exe 
    These prompts only occurs with domain user though its a member of administrator group on that local machine while logging with local administrator user this doesn't happen.
    Thanks
    REGARDS DANISH DANIE

    Hi Danie Danish,
    Would you please let me know current situation of this issue? Have you referred to britishdhez’s suggestion
    and solved it?
    Just additional. Please use anti-virus software to scan the server. Meanwhile, please run
    sfc /scannow command to check protected system files.
    If any update, please feel free to let us know.
    Hope this helps.
    Best regards,
    Justin Gu

  • Run Child Concurrent Program from Main Concurrent Program

    Hi,
    I'm trying to run Child Concurrent Program from the Main Concurrent Program as below, could you suggest me on below.
    Database:10g
    Main_Concurrent_Program
    =================
    1) Will update staging table XXID_PO_ITM with Batch_id = 1,2,3,4,5
    This staging table has 1000 rows, so every 200 rows will be updated with one of the above batch_id
    This logic is working.
    Child_Concurrent_Program
    ================
    2) Above Main Concurrent Program should call below Child_Concurrent_Program.
    This Child_Concurrent_Program will have parameter batch_id (based on above batch_id)
    So, this Child_Concurrent_Program should kick off with batch_id = 1
    Simillarly, Child_Concurrent_Program should kick off with batch_id = 2
    Child_Concurrent_Program should kick off with batch_id = 3
    Child_Concurrent_Program should kick off with batch_id = 4
    Child_Concurrent_Program should kick off with batch_id = 5
    Could you give me some suggestions on this?
    Thanks.

    Check with FND_SUBMIT for submitting a concurrent job using child dependecies. Keep in mind, that once you call the API ... it spawns it's own thread and and becomes an autonomous process. Control is no longer maintained within the calling package.
    procedure submit_interface_data(p_schedule_date in date,p_mm_header_id in number,p_req_id out number)
    is
      v_user_id            number;
      v_application_id     number;
      v_responsibility_id  number;
    begin
                select user_id
                into   v_user_id
                from   fnd_user
                where  user_name = 'USER123';
                select application_id,
                       responsibility_id
                into   v_application_id,
                       v_responsibility_id
                from   fnd_responsibility_tl
                where  responsibility_name = 'General Warehouse';
      fnd_global.apps_initialize(v_user_id,v_responsibility_id,v_application_id);
      p_req_id := fnd_request.submit_request ( application => 'XYZ',
                           program     => 'MOVE_CONC_SHORT_NAME',
                           description => null,
                           start_time  => p_schedule_date,
                           sub_request => false,
                     argument1   => p_mm_header_id);
      commit;
    exception
    when others
       then
         spl_log_pub.write_exception(transaction_id   => null,
                                     transaction_type => null,
                                     error_message    => '<some error message>' ||
                                     'sqlcode: ' || sqlcode ||
                                     'sqlerrm: ' || sqlerrm);
    end submit_interface_data;Edited by: sreese on May 18, 2012 3:16 PM

  • Running programs from within other programs

    I have a problem with running small java-applications form within another.
    If I put the BufferedReader for errors first, sometimes it gets stuck
    (without throwing any exceptions) when I want to run applications that
    are working without any errors, when I run them manually. But if I put
    the standardoutput-Reader first, it gets stuck (again without throwing
    any exceptions), when an error occurs. This "getting stuck" always happens
    in the line where the "while" is. It seems that nothing can be read, but its
    not null too.
    Thats part of my code:
    String cmd = "java -cp rightDirectory MyFile";
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(cmd);
    BufferedReader pout = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    String line2;
    while ((line2 = pout.readLine()) != null) {
    System.out.println(line2);
    pout.close();
    BufferedReader peout = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String line;
    while ((line = peout.readLine()) != null) {
    System.out.println(line);
    peout.close();
    How can this be done, that it works for all cases?

    hi, Have you read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html ?

Maybe you are looking for

  • ABAP OLE Word - Delete last page

    Dear all, I have a SAP program which prints some documents in Microsoft Word by using ABAP OLE Objects. I use a template to take the main context, and after that I send some variables in order to populate the word document. The problem is when I crea

  • P67A-C43 B2 Constant reboot when memory in DIMM1

      I just built a barebones kit consisting of: MB: P67A-C43 B2 PSU: Thermaltake TR2 RX 750W Bronze Proc: Core I7-2600 (unlocked) Mem: (2) 2x4 GB Corsair Vengeance DDR-1600 (16 GB) 9-9-9-24 Cool: Corsair H60 Hydro Vid: EVGA GTX 550 Ti HD1: OCZ SSD 120

  • Iphoto restored from backup with books created in iPhoto gone

    Anyone have any help? My Mac crashed, but fortunately had backed up my iphoto. Reinstalled now cannot find my books that were created...Need help on it might be the dog bed for me. Thx

  • NAT forwarding error?

    I have an Airport Extreme Base Station which I'm running with 3 pcs and a 12 inch powerbook - I used the powerbook to configure it. Everything works fine, except for 2 problems at specific online locations, which I suspect may be related. My online b

  • Multicast in Linux

    Hi,           Does anyone know how to add an IP address to a multicast address in Linux?           Do I have to use the "route" command?           Thanks,           Mo