Solved

Has the process finish? Runtime

Posted on 2002-05-03
9
236 Views
Last Modified: 2010-03-31
I am using Proces p1= Runtime.getRuntime.exec(cmdline)

to run a out a file.

I need to ensure that the file is produced before I can get into the step.

How can I ensure that the process has finished?


I have forgotten, it shd be something like getting a status back?

0
Comment
Question by:TLTEO
9 Comments
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6988193
TLTEO
You can get the result using the getInputStream parse it and know the status of it.

Shyam
0
 
LVL 92

Expert Comment

by:objects
ID: 6988213
Just cal:

p1.waitFor();

This will block until the process terminates.
0
 
LVL 2

Expert Comment

by:CSuvendra
ID: 6988224
Normal convention is to use Process.waitFor(), but it does not always work on Window$. This is an alternative from the Java forum.

*****************************************************
public RunProcess(String[] cmdarray,String[] envArray,String file)
    {
        try
        {
            Process p = Runtime.getRuntime().exec(cmdarray,envArray,new File(file));
               BufferedReader br =
                      new BufferedReader (new InputStreamReader(p.getInputStream ()));
               String s;
               while ((s = br.readLine ())!= null){
                   System.out.println (s);
               }
               
        }
        catch (SecurityException se)
        {
            se.printStackTrace();
        }
        catch(IOException ie)
        {
            ie.printStackTrace();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.out.println("Either cmdArray is null or empty");
        }
    }
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 92

Expert Comment

by:objects
ID: 6990840
> but it does not always work on Window$

Under what conditions does it not work?
0
 
LVL 2

Expert Comment

by:CSuvendra
ID: 6993017
This was something we had faced before. If the Application used dumps lots of output to the console, it fails (stops execution) after the 'out/ err' buffer reaches some specified value (I am unsure of this value).

We tried to use it with sqlldr, and after inserting 100 odd rows, no more rows were inserted. If you terminated the application using Ctrl+C, rest of the data (~10000 more odd rows) were inserted successfully ;-) - Isn't that funny ?

I don't seem to get the URL any more :-(
0
 

Author Comment

by:TLTEO
ID: 6998181
Can you elaborate on this

String[] cmdarray,String[] envArray,String file

on arrays??.  I don't thk I will need arrays .

0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 6998202
Have you tried waitFor() method?
0
 
LVL 2

Expert Comment

by:CSuvendra
ID: 6998330
This is something we used --

***********************************
import java.io.*;

public class RunProcess
{

    public RunProcess(String[] cmdarray,String[] envArray,String file)
    {
        try
        {
            Process p = Runtime.getRuntime().exec(cmdarray,envArray,new File(file));
               BufferedReader br =
                      new BufferedReader (new InputStreamReader(p.getInputStream ()));
               String s;
               while ((s = br.readLine ())!= null){
                   System.out.println (s);
               }
               
            //int i = p.waitFor();
            //OutputStream out = p.getOutputStream();
            //System.out.println(i);
        }
        catch (SecurityException se)
        {
            se.printStackTrace();
        }
        catch(IOException ie)
        {
            ie.printStackTrace();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.out.println("Either cmdArray is null or empty");
        }
    }
    public static void main (String[] args)
    {
        RunProcess process = new RunProcess(new String[]{"sqlldr","parfile=JDE_PARAM"},null,"Sample");
    }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 7004027
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JList custom Cell Renderer refresh 15 57
even odd program using while loop 3 40
login form jsp example 2 25
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 33
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question