Solved

Has the process finish? Runtime

Posted on 2002-05-03
9
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

724 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