Solved

Has the process finish? Runtime

Posted on 2002-05-03
9
248 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

730 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