[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Has the process finish? Runtime

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
TLTEO
Asked:
TLTEO
1 Solution
 
shyamkumarreddyCommented:
TLTEO
You can get the result using the getInputStream parse it and know the status of it.

Shyam
0
 
objectsCommented:
Just cal:

p1.waitFor();

This will block until the process terminates.
0
 
CSuvendraCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
objectsCommented:
> but it does not always work on Window$

Under what conditions does it not work?
0
 
CSuvendraCommented:
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
 
TLTEOAuthor Commented:
Can you elaborate on this

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

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

0
 
objectsCommented:
Have you tried waitFor() method?
0
 
CSuvendraCommented:
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
 
objectsCommented:
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now