System call fom Java code

Hi all
I hope someone over here might answer my problem.
I need to run a Shell script form my Java code, which does perform some operations like writing/copying files to a specific directory and my Java code then starts reading the files and do necessary stuff like parsing it for some info inside the file.
If I make a system call from my Java code, how do I know when the shell script is done executing completely? Just to make sure that my Java code execution starts only after the shell script has executed.
If anyone has come across such a scenario, please reply to this topic. A sample code wud be a bonus for me :)
Thanks
-Uday

If you've never used Runtime.exec, read this carefully first:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
MOD

Similar Messages

  • Call to JAVA code from VB

    i plan to write the interface(Presentation of the software, plz don't mistake it for java interface) in VB and all logic in JAVA...........Can you help me out. Is this possible? I mean can i make calls to JAVA code from VB ......?? Some references plz
    Thanks & Regards,
    Gurmeet S. Budhraja

    You can link the 2 projects VB and J# not Java, 'cause I don't think it's possible to like Microsoft to Sun

  • Stoping System Clock using Java code.

    Is it possible to do so if yes then some code idea for
    Stoping System Clock using Java code.
    [email protected]

    The system clock is controlled from the BIOS, and as such, I don't think even windoze can stop it, though it can be continually reset. I don't believe that Java provides a sufficiently low level of control to set the system clock, although you could use a native method to accomplish the task.
    Why would you want to do such a thing?

  • How to find the  System Dbtype in java code

    How to find the System Dbtype in java code
    I need various Db connection my project (oracle, sq l,sybase,db2),So How to find the System Dbtype in java code

    Welcome to the Forums.
    Please go through the FAQ of the Forum.
    You has posted your query in the wrong Forum, this one is dedicated to Oracle Forms.
    Please try {forum:id=1050}.
    Regards,

  • How to kill a system process from java code.

    Hi,
    i need to kill or remove windows system process like cmd.exe from java code.
    like removing it from end process in task mgr.
    i tried below code but its not removed.
    is there a better way we can do this.
    killing a system process from java code will create any issues?
       public static void main(String[] args) throws Exception {
       String[] cmd = { "cmd.exe" };
       Process p = Runtime.getRuntime().exec(cmd);
       p.destroy();
    any suggestions or ideas are really appreciated.
    thanks.

    Hi  jtahlborn, mohan
    yes the process is created from my java code. 
    in my code iam creating a process like below and if it is running for a long i need to kill it from java.
    For that " Runtime.getRuntime().exec("taskkill /F /PID " +  7408); " is working fine.
    7408 is my process id in taskmgr created from java and iam manually passing the PID it to kill it.
    But i need to get the PID from java code.
    Thanks for your suggestions.
    Sample Code:
    public static void main(String args[])
            try {
              Process process = Runtime.getRuntime().exec(new String[]{"cmd.exe","/c","start"});        
              Field f = process.getClass().getDeclaredField( "handle");
              f.setAccessible( true);         
              long procHandle = f.getLong( process);
              System.out.println( "prochandle: " + procHandle );
              //Runtime.getRuntime().exec("taskkill /F /PID " +  procHandle);
            } catch( Exception e) {
              e.printStackTrace();

  • Making system calls in java

    I want to join some split files into one. In command prompt I use COPY /B file.1+file.2 file to join the files. How can i do the same in my java application. Please show the code which I suppose will use getRuntime. Thanks in advance.

    Well if there is a problem with system calls then can
    you tell me if there is a class in java for
    concetanating files. Not directly.
    At present I am joing the files
    by reading each byte from the files and writing them
    to another file which takes hell lot of time. You should read the files in large chunks. Much much faster.
    Thanks
    in advance again. Also if you say about sequential
    file class then please expalin a bit bcs I couldn't
    implement it.Post the code you are having trouble with explaining what it should do and what it actually does.

  • Unix system() system call in Java

    Hi,
    system() call in Unix is very helpfull when you need to implement a piece of code that is already implemented in an exsiting utility.
    Is there a way to achive a similar functionality?
    To put it in simpler words - is there a way, in Java, to call some method that will invoke a Unix shell and will execute the command specified in the string that is past in?
    Could you please CC the reply to [email protected]
    Thanks,
    -Michael

    Runtime.exec()
    > Could you please CC the reply to [email protected]
    Certainly not.

  • Function calling the java code

    I have a java code that returns the size of the file name. I have created a pl/sql function that calls the method in the java class.
    The problem I face is , when I try to call the function using the command "CALL f_size('C:\Batch\Query.sql')into :leng " , the error comes reporting that
    "No method func in class fSize ".
    I have given both the java& pl/sql code. Can anyone help me out?
    import java.io.*;
    public class fSize {
    public static long func(String s)
    File file = new File(s);
    long length = file.length();
    return length;
    create or replace function f_size(path varchar2) return number
    as language java
    name 'fSize.func(String) return java.lang.Long';

    What version of the database are you runnning?
    If Oracle 9.2 or later, no need for java code. Use UTL_FILE.FGETATTR procedure.
    FGETATTR Procedure
    This procedure reads and returns the attributes of a disk file.
    Syntax
    UTL_FILE.FGETATTR(
       location    IN VARCHAR2,
       filename    IN VARCHAR2,
       exists      OUT BOOLEAN,
       file_length OUT NUMBER,
       blocksize   OUT NUMBER);
    Parameters
    Table 95-24 FGETATTR Procedure Parameters
    Parameters Description
    location
    Directory location of the source file, a DIRECTORY_NAME from the ALL_DIRECTORIES view (case sensitive)
    filename
    The name of the source file to be copied
    exists
    A BOOLEAN for whether or not the file exists
    file_length
    The length of the file in bytes. NULL if file does not exist.
    blocksize
    The file system block size in bytes. NULL if the file does not exist.
    SQL> create or replace and compile java source named "fSize" as
      2  import java.io.*;
      3  public class fSize {
      4      public static long func(java.lang.String s)
      5      {
      6          File file = new File(s);
      7          long length = file.length();
      8          return length;
      9      }
    10  };
    11  /
    Java created.
    SQL> show errors
    No errors.
    SQL> create or replace function f_size(path varchar2) return number
      2  as language java
      3  name 'fSize.func(java.lang.String) return java.lang.Long';
      4  /
    Function created.
    SQL>
    SQL> select f_size('C:\sqlnet.log') from dual ;
    F_SIZE('C:\SQLNET.LOG')
                        762
    1 row selected.
    SQL>
    SQL>
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.3.0 - Production
    SQL>

  • Unix System Calls using Java

    Hi!
    Can anyone tell me how to do Unix System Calls in my Java program?
    If possible please give me the java code for it taking one unix system call as an example.
    Thanks in advance
    Raj

    do you mean firing off a shell command, or making actual kernel API calls or C library calls?
    for shell commands, have a look at Runtime.exec(). for kernel calls, use JNI. the JNI FAQ mentions something called "shared stubs" that may be of use:
    http://java.sun.com/products/jdk/faq/jnifaq.html
    cheers,
    p

  • System Call by Java Application - [change path and run of the other progra]

    public class  A {
         public static void main (String[] args)
              System.out.println("Hi");
    }I do have above A.java.
    I am generating A.class from it.
    A.class is in the following directory :
    /home/sachin/work/Sample_Directory/bin/hello_filetest/
    I have another program which makes System call.
    But the problem is B.java is in the different directory :
    /home/sachin/work/Sample_Directory/src/hello_filetest/
    public class  B {
         public static void main (String[] args) {
    Process p1 = Runtime.getRuntime().exec("java A);
                BufferedReader stdInput = new BufferedReader(new
                     InputStreamReader(p1.getInputStream()));
    while ((s = stdInput.readLine()) != null) {
                    System.out.println(s);
    {code}
            So, my question is how to change directory by system calls and execute the program
    which is lying in other directory ????
    Thank you.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    The following code will call javac on a .java file, which will compile it into a .class file
         public static void javacTest() {
              JFileChooser jf = new JFileChooser();
              if (jf.showOpenDialog(null) != jf.APPROVE_OPTION) return;
              File file = jf.getSelectedFile();
              File dir = file.getParentFile();
              try {
                   Process p = Runtime.getRuntime().exec("javac " + file.getName(), null, dir);
                   IOUtils.pipe(p.getInputStream(), System.out);
                   IOUtils.pipe(p.getErrorStream(), System.out);
              catch (IOException iox) {
                   iox.printStackTrace();
         }Is that what you're trying to do, or are you trying to run the compiled (.class) file? Running your .class file should be basically the same as the above, assuming that you are not using any non j2se libraries, except that you need to take into account the package (if package is x.y, you must have file in ...src\x\y\foo.class - call "java x.y.foo" from src)

  • How to call external Java code from Animate project?

    I am creating a trainer using Animate that needs to interface with an aircraft model written in Java.  Is there a way to call external Java functions from Animate?
    Thanks!

    you can import external java files by yepnope
    yepnope({nope:[
                                  'your java script file address.js',
                             ],complete: init});
    function init() {
    codes that work with your js file can be write in here
    Zaxist

  • Calling simple Java Code from 11g BPM

    Hi,
    I know this has been round the houses but I cant find a satisfactory solution for my scenario. I would like to call some simple java code from BPM (11.1.1.6). I guess I need to expose it as a service but it seems overkill to be via soap so any advice you can give would be much appreciated. Creating a jar that I can call somehow would be perfect.
    This is my scenario:
    - I am creating a Security POC for BPM
    - The BPM Process is exposed as a web service and authenticated using SAML
    - I am testing by calling the WS from OSB
    - I want to be able to get the WLS Principal and display the username and the roles for the launching user, from within the BPM process
    - This is possible using some simple weblogic client api code shown below
    - So all I want to do is call this code from BPM somehow
    - Anyone point me in the right direction ?
    cheers
    Tony
    subject = Security.getCurrentSubject();
    for(Principal p: subject.getPrincipals()) {
    if(p instanceof WLSGroupImpl) {
    groupList.add(p.getName());
    } else if (p instanceof WLSUser) {
    principal = p.getName();
    }

    The problem to communiate java classes and forms solved !
    i have add my .jar file to $OA_JAVA/oracle/apps/fnd/jar and now i can communicate between forms and java.
    I can create an object, i can get simple message from class, but when i try to create
    ServiceFactory factory = ServiceFactory.newInstance();
    ive got ORA-105100...
    can anybody help ?

  • Can we call Plain JAVA Code online via MDM Cient

    Hi SDNers,
    For some validation purpose i need to write a JAVA Code(Some body told me that it can be possible i.e we can Java Code for doing Validation)
    i have two Questions.
    1. Can we call JAVA Code online via MDM Client.
    2. where i have to write this JAVA Code and what will be steps of writing this Code.
    Thanx in Advance.

    Hi Tanveer,
    Thanx a lot for ur prompt reply
    Pls reply my this Question also promptly i will be highly thankful for it.
    Q.
      My Requirment is i have to do the validation
      "on the basis of acct grp i have to put validation
          a. the G/L acct must be in particular range.
          b. it must have specific length"
    My sr. developer is saying simply putting the IF ELSE condition in the validation Editor technique 'ld be hard to maintain at later stage as we large number of Acct Grps.
      He is saying look for some Custom function for it
    "SO TELL ME CLEARLY THAT
                                                   --CAN I USE JAVA API FOR THIS
                                                   --AS A EXP. MDM CONSULTANT WILL U
                                                      RECOMMEND IT?
                                                   --IF YES
                                                     THEN
                                                          WHAT 'LD BE EXACT STEPS.
                                                 ---IF NO
                                                    THEN
                                                         WHAT ARE THE OTHERS WAYS
                                                         i.e
                                                         IF U R FACING THIS PROBLEM THEN WAT
                                                         SOLN U R GOING TO USE?
    PLS
    REPLY ASAP as per the exact question(i.e all parts of Q)
    i will highly thank for u.
    Regards
    kuldeep

  • System calls in Java

    Any suggestions how one would perform a UNIX call inside a C++ or Java program?
    Student who needs help.

    If it is really a system call, then you will have to define and implement a "native" method.
    o java method witha "native modifier".
    o write a small c program that implements the method
    If you define the native method, and then run java.h, the result is a header file for the c program.

  • System Call from Java, problem LD_LIBRARY_PATH

    I use class Runtime to invoke Operating System Call.
    I want to run OS command gpg (gnu program for encrypting/ decrypting files).
    What is interesting, when I run my sqlplus script from system user (used for database installation) call ends with success.
    Running script from other os users or machines ends with -1 code and error message:
    "ld.so.1: gpg: fatal: libiconv.so.2: open failed: No such file or directory"
    gpg uses libraries given LD_LIBRARY_PATH (/opt/gnupg/lib:/usr/lib:/usr/local/lib)
    I think that is the problem. Is there a workaround for that??
    Best regard
    Grzegorz

    Maybe related to the fact that the PATH environment variable is unset then re-initialized by Oracle to PATH = /usr/local/bin:/bin:/usr/bin. Try using absolute path for the OS commands.
    Kuassi
    - blog http://db360.blogspot.com/
    - book http://db360.blogspot.com/2006/08/oracle-database-programming-using-java_01.html

Maybe you are looking for

  • Lack of Trade in trade up support this time around

    I noticed last time there seemed to be a lot more willingness to help from Best buy admins on here...what happened?  They even have the old promo details still up at the top of this page.

  • Generating web PL/SQL Form header (MODSHD) including modulename

    Hi all, I want to generate a WEB PL/SQL form using a template. The call to the stored function goes fine. I call package.function which returns a string, that is displayed. So far so good... However, I want to display the name of the Module (or some

  • My Hyperlink button not working in FaceBook

    I created a slide show and a link to my web site and to music site. When I upload the QT file to FaceBook, the buttons are there, but no link. David

  • Moving Movie Clips dynamically

    Here's the deal. I have a function that I call to move the movie clips based on string that holds the movie clip instance name. The function as I have it now can be seen below listed under figure A. Figure B shows my call to that function. It takes i

  • Could you tell me what is the reason behind all this?

    Hi   Zp0001, we have 510 pcs in stock, but for some reasons we can’t commit the orders that we have on the system. When we go into a xyz order 308 for example), the system commits only to February, even if we could do a partial shipment. Could you te