Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to create an independent process in java

843798May 26 2008 — edited May 27 2008
Hi ,

I want to execute a dos command from a java program.

The code is shown below.
Process p;
ProcessBuilder pb;

command[0] = "cmd";
		command[1] = "/C";
		command[2] = "C:\\plink.exe -v -N -L 33890:10.103.1.87:3389 -l graja 10.100.32.100 -i C:\\putty_private.ppk -pw xxxxx \n";

        pb = new ProcessBuilder(command);
        p = pb.start();
The purpose of this program is create an ssh tunnel to the specified host .i.e 10.100.32.100 (here).

The problem i am facing here is, the tunnel is not created until the main program which creates this process is exited.

My requirement is ..the main program and the process should be run at the same time.

*plink is the command line version of PuTTY tool.


* I tried this with one level threading and two level threading also. but it couldnt workout.



*********************************************

Hi,



This looks to be very small.

I wish to create a process which executes a DOS command ( It is one which deals with network connections).

I have written a small program, which creates a process that executes the DOS command.

Until the main thread or process is exited , the connection is not establishing..

In my project , the main() thread should create a process and continue with remaining program.

For this , i have tried with 2 levels of threading , but i couldn't get through.



This is the code of main program:
public class abc {

public static void main(String[] args){

String[] command =  new String[3];
        command[0] = "cmd";
        command[1] = "/C";
        command[2] = "C:\\plink.exe -v -N -L 33890:10.103.1.87:3389 -l graja 10.100.32.100 -i C:\\putty_private.ppk ";

        
Process       p = Runtime.getRuntime().exec(command);      
}
First , i tried with putting this code in the main function itself.

Second, i tried with putting this code in a thread(), which is created and started by main() function ---one level threading. like the below...
public class  hello extends Thread
{
    public Process p ;
    
    public void run()
    {
        try{
       
        String[] command =  new String[3];
        command[0] = "cmd";
        command[1] = "/C";
        command[2] = "C:\\plink.exe -v -N -L 33890:10.103.1.87:3389 -l graja 10.100.32.100 -i C:\\putty_private.ppk ";

        
        p = Runtime.getRuntime().exec(command);       
       
       
        }catch(Exception e)
        {
            e.printStackTrace();
        }
        
    }
   
    
   public static void main(String[] args) throws Exception
    {
       hello h = new hello();
       h.start();

   }

}
       
Third , i tried with putting this code in a thread which creates another thread which creates this process.


But problem was not solved



Can anybody please help me in this?


Thanks,
Raj

Edited by: raj143shi on May 26, 2008 11:39 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 24 2008
Added on May 26 2008
1 comment
1,007 views