Solved

Has the process finish? Runtime

Posted on 2002-05-03
9
216 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
 
LVL 92

Expert Comment

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

Under what conditions does it not work?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array220 challenge 8 45
count11 challenge 6 47
computer science syllabus 3 52
Java Message handling in Service Layer 3 37
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now