How to create an independent process in java

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

Need not to use thread for this.
Once you execute the command..job is done at that time only.
Check the example below
1. While the main thread is sleeping your output file (a.txt) is created in C:\
import java.io.IOException;
public class abc1 {
    public static void main(String[] args){
    String[] command =  new String[3];
            command[0] = "cmd";
            command[1] = "/C";
            command[2] = "DIR >> c:\\a.txt";
            try {
             Process p = Runtime.getRuntime().exec(command);
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    try {
     Thread.sleep(50000);
     System.out.println("Slept for 50 secs");
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
}

Similar Messages

  • Creating a Batch Process in Java

    Hi,
    I have to create a Batch process in Java but I have no idea how can I do that: "Kind of java project I have to create ....
    Thank you for your help.

    Hi,
    I have to create a Batch process in Java but I have
    no idea how can I do that: "Kind of java project I
    have to create ....
    Thank you for your help.Hi,
    I suggest you some methods to create executables for java
    These are the steps::
    1=>Compile all the java classes
    2=>create a Manifest.txt file with Main-Class : (class name where the execution starts ie class which has public static void main(String args[])function
    3=>create a jar
    After creating a jar file there are 2 ways you can make it to run by single click
    1==> you can create a .bat file
    2==>you can convert the jar file in to .exe file by a software
    creating .bat file
    assume let the file is D:\java\hello.jar
    run.bat
    go
    java -jar "D:\java\hello.jar"
    2==> this is the better method and the software which i have is vey convienent to use
    if you need it i can mail you

  • How to create a "Explorer" like in java

    i'm just wonderin if there's a way on how to create "Windows Explorer" like in Java wherein you can view all your directories with yellow folder icon and also you can view all your files and drives....
    And when you double click the yellow folder icon it will then expand and will show all the subfolders and files ...
    How????
    Thanks!

    Yes, there is a way. Look up JTree in the API.-can you post some code.... i cant figure out on how to use JTree...
    i'm still confused on where will i get the entire directories of my drives...
    thanks

  • How to create a Batch file for java application  ?

    HI,
    How to create a Batch file for java application ?
    And whats the use of creating batch file ?
    Thanks in advance

    [http://static.springsource.org/spring-batch/]
    Assuming you want to develop a batch application rather than actually just create a .bat file ..

  • HOw to create a Batch file for java application and whats the use of this ?

    HI,
    How to create a Batch file for java application ?
    And whats the use of creating batch file ?
    Thanks in advance

    First of all, you're OT.
    Second, you can find this everywhere in the net.
    If you got a manifest declaring main class (an classpath if needed), just create a file named whatever.bat, within same directory of jar file, containing:
    javaw -jar ./WhateverTheNameOfYourJarIs.jar %*By the way, assuming a Windows OS, you can just double click the jar file (no batch is needed).
    Otherwise use:
    javaw -cp listOfJarsAndDirectoriesSeparedBySemiColon country/company/application/package/className %*Where 'country/company/application/package/' just stands for a package path using '/' as separator instead of '.'
    Don't specify the .class extension.
    Javaw only works on Windows (you asked for batch, I assumed .BAT, no .sh), in Linux please use java.exe (path may be needed, Windows doesn't need it 'cause java's executables are copied to system32 folder in order to be always available, see PATH environment variable if you don't know what I'm talking about) and use ':' as classpath (cp) separator.
    The '%***' tail is there in order to pass all parameters, it only works on Windows, refer to your shell docs for other OSs (something like $* may work).
    This way you have a command you can call to launch your code (instead of opening NetBeans just to see your app working). You could schedule tasks on it or just call it in any command prompt (hope you know what it is 'cause there have been people in this very same forum with no clue about it, if not just hold the 'Windows button' and press 'R', then type 'cmd' and run it).
    Finally add dukes and give 'hem away.
    Bye.

  • How to create the exe file for java project.

    How to create the exe file for java project.
    am done the project in java swing , i like to create the project in exe format, so any one help for me,
    send the procedure for that.
    thanking u.

    How to create the exe file for java project.Have you ever heard of google? I pasted your exact "question" into a google search:
    http://www.google.com/search?q=How+to+create+the+exe+file+for+java+project.
    and got several useful links.
    Better search terms might yield even better results.
    Sheesh.

  • How to create document in process chain

    Hi,
    can u plz tell me how to create document in process chain and wat i need to edit the text for particular info package when document.

    Hi Anil,
    Goto Tcode:RSPC and select your load data process type where you have to right click on the process chain and select Select create message,there are three types of messages
    1>Successful
    2>Error
    3>Always
    If you already created message then go to maintain message
    Where you have two buttons
    1>is for Edit Document
    2>Maintain Recpiants
    Goto Edit Document and put your comment and set their mail address in Mail recipiants.
    Note there are 2 types of messages you can kept at execution of infopackage process type.
    If load is successful send the mesaage to recipients
    If load is failed send the message to mail recipt.
    It would help you.

  • How to create a  schedule program in java

    Hello Friends ,
    Can any one provide me with an example how to create a schedule program using java.util.timer etc . I am in need of a program which should run as a schedule job that searches for a file in a directory and read the latest files from that directory in every minute of time as a schedule job .
    Thanks
    mahesh

    I don't feel like writing my own example, but google will be happy to provide you with an example.

  • How to create a packet by using java?

    Hi, i am currently working on a research and i have some problems here.
    1) how to create a packet by using java programming ?
    2) How can i set the packet's information (e.g: packet's length, size of its header, etc) by using java?
    I am currently in a midst of this now and i hope that someone is willing to correspond to my questions and help me out of it.
    Thank you!

    I wan to create a customize packet where the user can
    define the header size, the packet's length etc. in
    the program......Then you get to write it to the connection yourself. Look at the OutputStream classes to see how to write low level output to a connection.

  • How to create a oracle database by java code?

    how to create a oracle database by java code?
    please give some ways then that way's code

    I'm not sure what you mean with "database". Do you mean an Oracle instance or an Oracle user/schema (probably the latter, because that's the equivalent to a MS SQL Database).
    Creating an instance is definitely not possible from within Java. To create a new user this should be possible, as this can be done with SQL:
    GRANT connect,resource TO <newuser> IDENTIFIED BY <password>;
    I'm always cautious with questions like this. In 90% of the cases there is something wrong with the initial design. Creating a database shouldn't be something the application is doing.
    Thomas

  • How to create a SAS Dataset with Java

    Hello All,
    The subject line says it all. Does anyone out there know how to create a SAS Dataset using Java? I Googled it and searched here with no luck.
    Thanks
    KP

    Some parts of SAS appear to have been exposed via a Java API through this product:
    http://support.sas.com/rnd/app/da/workshop/faq.html
    Hope that helps
    Lee

  • How to create an Oracle DATABASE through Java Programming Language.. ?

    How to create an Oracle DATABASE through Java Programming Language.. ?

    Oracle database administrators tend to be control freaks, especially in financial institutions where security is paramount.
    In general, they will supply you with a database, but require you to supply all the DDL scripts to create tables, indexes, views etc.
    So a certain amount of manual installation will always be required.
    Typically you would supply the SQL scripts, and a detailled installation document too.
    regards,
    Owen

  • How to create Short Lived process?..can neone pls help...

    How to create Short Lived process?..can neone pls help...

    Hi,
    Login into workbench. Click on Help->Workbench start page.
    Lot of helps are there you can go through them. They will be helpful.
    But it seems you are new to livecycle, so it will difficult to start through help. Either you can take help of any of your team member who is expert in livecycle or some training you should attend.
    Thanks

  • How to create the exe files for java application

    How to create the exe file for java application?
    got any software to do that?
    Thanks

    In terms of converting java applications into exe files, there are 3 schools of thought:
    1) Instead of converting it to an exe, convert it to a jar file. Jar files are more portable than exe files because they can be double-clicked on any operating system. The caveat is that a Java interpreter must be installed on the target computer for the double-clicking to work.
    http://developer.java.sun.com/developer/Books/javaprogramming/JAR/
    2) Create an exe launcher that, when double-clicked, attempts to find a Java interpreter on the local computer and launches the Java application. The exe file is still double-clickable but whether your java application runs depends on whether a Java interpretor is installed on the target computer.
    http://www.sureshotsoftware.com/exej/
    http://www.objects.com.au/products/jstart/index.jsp
    http://www.duckware.com/products/javatools.html
    http://www.ucware.com/jexec/
    http://www.rolemaker.dk/nonRoleMaker/javalauncher/
    http://www.jelude.cjb.net/
    http://thor.prohosting.com/~dfolly/java/index.html
    3) Create an exe launcher that bundles a Java interpretor. Same as above but when the exe file is double-clicked, it searches for a Java interpreter and if one is not found, it installs one on the target computer. The caveat is that the exe file would have an overhead of 10 MB in size for the interpreter.
    http://www.excelsior-usa.com/jet.html (evaluation version available)
    4) Convert the Java application into a native exe file. The caveat is that if you use Swing for your GUI, it won't be converted. Also this option is still somewhat experimental.
    Can't think of any free options right now.

  • How to create a Macromedia's Flash Java Player with JMF?

    How to create a Macromedia's Flash Java Player with JMF? Can you give me an example? My email:[email protected] [email protected]

    Yes, there is a way. Look up JTree in the API.-can you post some code.... i cant figure out on how to use JTree...
    i'm still confused on where will i get the entire directories of my drives...
    thanks

Maybe you are looking for

  • Error while promoting  the repository to a global repository

    Hi, After restoring the repository, I try to promote the repository to a global repository in an Exclusive mode. When check the Global Repository check box and click OK. Pops up User name & password. I have used[i] admin user name and password. It gi

  • Adobe Media Encoder CS4

    Adobe Media Encoder CS4 has one Filter ... Blur , is it possible to add another and are there any available, specifically for adjusting gamma. Thanks

  • Moving an image around in a drop zone in DVD studio

    Hi there I am pretty new to this DVD studio program, and I often am using templates to make my client DVDs. One major major problem I always come across is when I have to drop images in, they always dont fit properly, let me show you one for example

  • Bill Payable

    when we process to pay bill for vendor through bill payable account i getting error that  cannot directly posted to reconciliation account. I using posting key is 39. I am new to FI please suggest what i have to do.

  • AE CS4 hangs while rendering to AVI

    (running CS4 on Win XP Pro x64 on a quad core Opteron system with 4GB memory) I have a fairly long composition (8744 frames) that I used to render just fine on this system with AE CS2. Then I upgraded to CS4 (and subsequently had my .aep file convert