Runtime.exec not releasing lock on files

Hi,
I am using Runtime.exec to launch an external application, a batch file that runs a java program and generates a pdf file on disk. The Runtime.exec is called from inside the callback function of a toolbar button in my UI. Once, the runtime.exec returns, I popup a alert saying "pdf generated successfully". However, when I try to open the pdf that has been generated, I get a message saying the "program is in use by another program" or some such message. Only when I quit my GUI application, Iam able to open the pdf file using acrobat reader.
Can someone tell me how to solve this problem. I have tried doing proc.waitFor() etc.
Cheers,
vidyut

You can try some of sysinternals tools to look through file sharing information and decide what process is locked file.
PS Try to ensure that you start java in same process as batch file executes, overthise you just can't ensure it terminates on time.

Similar Messages

  • 3.0EA1: Trace files locked on open and not released on closing file

    I have discovered that SQL Developer locks trace files when they are opened (at least on Win XP SP 3), which it doesn't do with sql or pl/sql files. Also, even after closing the file in SQL Developer, the lock isn't released - you need to close SQL Developer to release the lock to be able to move/rename/delete the trace file.
    theFurryOne

    I was able to replicate this as well. I am forwarding it onto a developer to take a look at this. Thanks.
    Ashley
    SQL Developer Team

  • Why is Runtime.Exec not perfekct?

    Hi!
    I need to execute a program from java using Runtime.Exec(). I have done everything right with redirection the output stream and read it from a seperate thread. This works for most of the programs I tried, but not for all. Sometimes I miss some of the output.
    But if I use redirection to a file from the shell it works perfect.
    (i.e. /bin/pramsim > outfil)
    Why is this? Why isn't Runtime.exec as good as shell redirection?
    /Karl

    Ok sorry, here is some more detalis.
    The program( pramsim) prints to both standard output and standard error. Output written to stderr does always work. But output so stout fails quite often. After some research I found out that pramsim is using the function printf(...) which is bufferd by default. So I only get the output when the program prints alot, so the buffer gets full.
    Can I in some way turn buffering off from java? Found a C function called setbuf(1,null) which turns buffering off. But this means I have to changes the code to pramsim, and I want to avoid that!
    I also wonder: How does redirection in the shell make this work. I guess buffering is turned off when I redirect to a file using 'pramsim > outfil'. (maybe this is more a C question but I hope that I can get some help here)
    /Karl

  • Runtime.exec not executing the command !

    Hi all,
    I'm connecting to Progress Db thru JDBC trying to execute a stored procedure
    which has a statement
    Runtime.exec("ksh -c aa") where aa is aunix script which i'm trying to run from java snippet .
    when i run this code as a seperate java program it executes the script
    "aa" but thru JDBC connection it does not execute the command
    what could be the reason ???
    thanx in advance,
    Nagu.

    Hi Rick,
    "aa" is the shell script which is lying in the user DIR .
    It is returning a non-zero value. what kind of permissions be there for to execute the Shell command?
    Regards,
    Nagarathna.

  • Oracle select for update: not releasing lock

    My JDBC code uses "select for update" to modify record in Oracle database. I tried to simulate network connection down situation.
    After my JDBC code locked on a record using "select for update", I unplugged the network cable. I then tried to run the same code on another computer, but it could not accquire the lock, because the previous lock was not released. I tried sqlplus to lock the record, but failed also. The lock has been there for at least an hour now. I guess it may finally be released, but is there a way for oracle to release the lock as soon as the connection is down? Not know if it is a JDBC setting or oracle setting.

    Dear Friend,
    What you are trying to do is not correct way of checking the concurrency and transaction.
    The reason is as listed below.
    01.Always remember http is a stateless protocol and removing the connection or just closing the browser will never be informed to the database or to the application server thus the transaction monitor (TM)or processor will never release the lock as it will deem that the actor is manipulating the data.
    02.As per locking goes every database is having a �TM� and the default isolation level setting is different like oracle uses serializable DB2udb 7.0 or db2/As400 uses repeatable read. You can change this setting by editing the default setting in the database but be very sure before touching it.
    03.     You can also transpose this with your Application server setting for that piece of code or Globally but again be very sure about it as it will change the entire gamete.
    04.     For releasing lock you have to manually do it or you can change the settings of App server or the Database to release the connection after some wait time.
    Regards,
    Ruchir

  • Runtime.exec( )..can't find file

    Hi,
    i'm passing the path of a file to runtime.exec()
    but yet it's searching for the file in the working directory.
    exec is getting the following
    String [] command=new String[2];
    command[0]=new String(applicationToExecute);
    command[1]=new String(fileName);
    try {
    Process child = run.exec(command);
    }catch(){}.....
    applicationToExecute="mspaint.exe"
    fileName="c:\temp\time.jpg"
    However,
    it searches the working directory (directory which my program is running from) for "time.jpg".
    any ideas?
    help would be appreciated!
    finbarr
    it searchs

    Try to provide the full path to the command and use the forward slash instead of the backslash -- like this:
    String [] command=new String[2];
    command[0]=new String("C:/Program Files/Accessories/mspaint.exe);
    command[1]=new String("C:/temp/time.jpg");
    If that still doesn't work, then try this:
    String [] command=new String[3];
    command[0]=new String("command.com"); // or just cmd on XP
    command[1]=new String("C:/Program Files/Accessories/mspaint.exe);
    command[2]=new String("C:/temp/time.jpg");
    V.V.

  • Runtime.exec--problems writing to external file

    Hi. I went to http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html, and am still quite confused regarding the use of Runtime.exec, for my purposes. I want to decompile a CLASS file using javap, and then write that to a TXT file, for easier reading/input to JAVA. Now, I use the following code (a modification of what I got from http://www.mountainstorm.com/publications/javazine.html, as the "traps" article's sample code is WAY too confusing--they say the compiler had the output sent to text.txt, without even showing how in the source code they did that), but it hangs up. Modifications to the string array cause different results, such as showing the javap help menu, or saying that the class wasn't found, but I think the way I did the array here is right:
    import java.util.*;
    import java.io.*;
    public class Test {
            try {
             String ls_str;
                String[] cmd = {"C:\\j2sdk1.4.2_04\\bin\\javap", "-c", "-classpath", "H:\\Java\\metricTest", "metricTest > blah.txt", ""};
                Process ls_proc = Runtime.getRuntime().exec(cmd);
             // get its output (your input) stream
             DataInputStream ls_in = new DataInputStream(
                                              ls_proc.getInputStream());
             try {
              while ((ls_str = ls_in.readLine()) != null) {
                  System.out.println(ls_str);
             } catch (IOException e) {
              System.exit(0);
         } catch (IOException e1) {
             System.err.println(e1);
             System.exit(1);
         System.exit(0);
    }

    Also, jesie, I realize that's what I need...the only
    problem is, the name "test.txt" is nowhere to be found
    in the source code! lolLooks like I have to explain this, then.
    When you look at a Java program you'll notice that it always has a "main" method whose signature looks like this:public static void main(String[] args)When you execute that program from the command line, it takes whatever strings you put after the class name and passes them to the main program as that array of strings. For example if you run it likejava UselessProgram foo bar hippothen the "java" command takes the three strings "foo", "bar", and "hippo" and puts them into that args[] array before calling the "main" method.
    That means that inside the "main" method in this case, "args[0]" contains "foo", "args[1]" contains "bar", and "args[2]" contains "hippo".
    Now go back to the example and see how it lines up with that.

  • Using Runtime exec() method to run java files and return runtime errors

    Hi
    I'm writing a java editor and I use
    Runtime.getRuntime().exec(command)
    to compile the java files. That works fine and I deal with the returned errors using the getErrorStream().
    My questions are:
    1. Can I use the same technique for returning runtime errors. In any posts I've read the process runs from begining to end, returning the errors after completion. How do I return the errors of the app as they happen interactively?
    2. If i cant use the exec and getErrorStream() methods then does anyone know how it is done?
    Thanks in advance for any help!

    Read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    MOD

  • Why runtime.exec() not working?

    I just want to run "ls" i unix on my JSPs.
    Process process;
    Runtime rt = Runtime.getRuntime();
    String line;
    process = rt.exec("ls");
    Here's the error message.
    java.io.IOException: ls: not found

    On my Linux
    rt.exec("ls");
    does work.
    If, on your system,
    which ls
    does not return an external executable like /bin/sl, try this command line:
    import java.io.*;
    public class Ls{
      public static void main(String[] args){
        String line = null;
        try{
          Runtime rt = Runtime.getRuntime();
          Process prc = rt.exec(new String[]{"sh", "-c", "ls"});
          InputStream is = prc.getInputStream();
          BufferedReader br = new BufferedReader(new InputStreamReader(is));
          while((line = br.readLine()) != null){
            System.out.println(line);
          prc.waitFor();
        catch (Exception e){
          e.printStackTrace();
    }

  • Not releasing locked record

    When connected to oracle server and modifying some record. The
    client is switched off without disconnection. Once connected it
    is not allowing me to update the same record saying 'CAN NOT
    RESERVE RECORD for UPDATION ?'
    Resources are released after a long time
    So what is the solution. Which parameter needs seeting

    Ajay :
    Do you know how I can read data from a Text file into a Parameter Table in eCATT ?
    I created the file by downloading the Variant from the Test Data container and updated it using XLS.
    I also have named my parameter reference with my structure and added '[]' to it at the end.
    I haven't had any success reading the entries into the parameter table.
    Thanks
    Naresh.

  • PSE 13 keeps crashing for no reason, Win 8.1 64. From Task Manager looks like PSE is not releasing memory when file closed

    and since there is no autosave feature in PSE (unlike PS) , you lose your work...

    I read this morning on another forum that closing the info. palette prevented "freezing" that the user experienced in PSEv.13. I don't know the difference between freezing and crashing in this context.
    Try it, nothing to lose. Please post back.

  • File lock not released

    Hi,
    I am unable to delete certain files as JDeveloper does not release locks on them. One use case is when I run a build file to create a jar, war or ear file. After executing the builld, I open the file (this is when JDeveloper locks these files, I think) to check the structure and contents of the generated file. Trying to run the build again fails because, JDeveloper does not release the locks on existing file that was generated during the previous build. I have to restart JDeveloper to delete the file.
    Thanks

    In the meantime if you are working on the XP platform (I am guessing) then you might want to venture a look at this little program called Unlocker that is a free little utility that shows what process is grabbing the file and preventing deletion or modification and then presents to you suitable options of what to do in that situation. I have used it countless times and it works like a charm.

  • Runtime.exec() does not work?

    I'm trying to invoke a C++ executable from java using the Runtime.exec() method. The C++ application accepts a filename as a command line argument & opens the file. This C++ app is unicode enabled i.e. it can accept UTF-16 (wide char) parameters. Howevere, when i invoke this application using Java's Runtime.exec() and specify a japanese file name as an argument, the japanese characters get converted to '?' characters by the time they are received in the C++ application. I'm running this application on Windows 2K, default i.e. English version.
    Looking at the source code of Runtime class, it seems that the exec()
    function makes use of a native helper function - execInternal(). Does
    this function support the entire unicode range?
    Is there any way we can avoid the conversion of japanese characters to '?' characters? Also, is there any other alternative for invoking an external application with Unicode (Say, japanese) arguments?
    Please reply ASAP.
    Thanks!

    >
    I'm trying to invoke a C++ executable from java using
    the Runtime.exec() method. The C++ application accepts
    a filename as a command line argument & opens the
    file. This C++ app is unicode enabled i.e. it can
    accept UTF-16 (wide char) parameters. Howevere, when i
    invoke this application using Java's Runtime.exec()
    and specify a japanese file name as an argument, the
    japanese characters get converted to '?' characters by
    the time they are received in the C++ application. I'm
    running this application on Windows 2K, default i.e.
    English version.
    Looking at the source code of Runtime class, it seems
    that the exec()
    function makes use of a native helper function -
    execInternal(). Does
    this function support the entire unicode range?I don't know because I've never tested this case specifically.
    You didn't show your code though. How are you reading in the String? You mentioned that you passed a Japanese character String as a filename argument. I also read that you are running on an English Win2K platform. How did you read that argument in? It may just be that you read the argument in your default encoding(English) and you needed to specify an alternate one.

  • Using runtime.exec,process streams

    Hi all,
    I am using runtime.exec to execute a batch file(rmdir /s/q directoryname) which deletes all the files in a certain directory(including subdirectories). However, some of the files are not deleted since they are being used by other processes.
    I have closed all file references but still the batch file says they are being used by other processes. The File.canWrite() method however, returns true for all the files. I have also tried to delete the files using file.delete but it does not work.
    So I have 2 questions.
    1. Can I forcibly delete these files some other way.
    2. If i call a batch file to delete the files and it fails on some files, the command window displays "cannot delete files". How can I write out thse messages into a text file which i can use as a log file.Do I have to use Process.getInputstream()/Process.getInputstream() ? If so, how?
    Thanks for your help.
    Vinny

    I tried the following before but the string i get is always empty, but i can see there are messages in the command window. Please let me now if i am doing something wrong.
    try{
    Process p = rt.exec("cmd.exe /c start deletefiles.bat");
    InputStream ins = p.getInputStream();
    byte[] bytearray = new byte[1024];
    int bytecount;
    String dos_string="";
    BufferedInputStream bis = new BufferedInputStream(ins);
    while ((bytecount = bis.read(bytearray, 0, 1024)) > -1) {
    String str = new String(bytearray,0,bytecount);
    dos_string += str;
    System.out.println("dos string is" +dos_string);
    catch (Exception e) {
    System.out.println("Error: " + e);

  • Running C++ application from Runtime.exec

    Hello everybody
    I am trying to run a c++ executable file(myap.exe) using Runtime.getruntime().exec("myap"), nothing happend!.
    Can anyone help me please.

    Where is located the file 'myapp.exe' ?
    If not in directory that is in 'PATH' varable, you need to use :
    Runtime.exec(String command, String[] envp, File dir)
    Executes the specified string command in a separate process with the specified environment and working directory.
    Floweb

Maybe you are looking for

  • How to transport the report object from development clint to quality clint

    any body knows different ways of transferring  report object  from  development clint to quality clint.pse send ...

  • Application crash with Lexmark X63/ Win2000

    When printing any report longer than one page, the report printer aborts and control does not return to Oracle Forms. The forms application must be killed by the task manager. Running the reports from the report builder has the same result, and repor

  • I can't see the "Render work area"

    Gentlemen ! I work with Adobe CS4 AE fully updated Ram 6GB Footage 1920x1080 24fps Windows 7 Ultimate Well, if I am not mistaking , there was something called " Render work area" as well as  " Render effect area" Evertime I wanna sync a part of a son

  • Need help in POI plugin in java

    Hi, I am doing a monthly status report using POI plug-in. Now i am having problem: for example to SUM the cells to one cell: Example : A1=SUM(A2+A3) ( its working fine) but if i do SUM for more cells using " : " this caracter its not working :( =SUM(

  • Adobe Media Encoder reinstall?

    I installed Flash CS4 a couple of days ago. Trying it out for the first time today. I went to import a video & got a message: "The required version of Adobe Media Encoder is not installed or the installation is damaged. Please reinstall." I'm showing