About runtime.exec("passwd")

In solaris,you can use command "passwd" to change password of user.
Now i want to use the command in java.But i can not get the result like below:
%new password:(type the password)
Re-type password:
my codes is copied here,please help me .
import java.util.Enumeration;
import java.io.*;
import java.lang.*;
public class liu{
     public static void main(String args[]) throws Exception{
          try{
               Runtime rr=Runtime.getRuntime();
               String[] aaa={ "passwd"};//passwd liuyang"};//ls -l"};
               Process cess=rr.exec(aaa);
          String sss;
               DataOutputStream out=new DataOutputStream(new BufferedOutputStream(cess.getOutputStream()));
//               out.writeBytes("qwerty\n");
               out.writeBytes("OUTPUT");
               out.flush();
               DataInputStream in=new DataInputStream(cess.getInputStream());
               while((sss=in.readLine())!=null)
                    System.out.println(sss);
          }catch (Exception ex) {
               System.out.println("Exception:"+ex);

I would really recommend not to code your own password utility in java. Yours will be insecure and will echo onto the screen whilst the default unix one will be as secure as sun can make it.
Jon

Similar Messages

  • Question about Runtime.exec

    Rob,
    Thanks for your help.
    I asked a question about a weird Exception on Nov 14, and you told me that I am
    using Runtime.exec to start an external process, and that process is crashing.
    I am a green-hand on Weblogic, and I am trying to enhancing a project developped
    by another person, so I am not familiar with some concepts yet.
    Could you please give me some simple explanation about Runtime.exec and external
    process?
    I found two methods that uses "Runtime" from two classes as following, could you
    help me to see whether or not there is something wrong with the usage of Runtime?
    Thank you very much.
    private int runShellCommand(String command) {
    int exitVal = -1;
    try {
    File runDir = new File(runDirectory);
    String[] env = new String[0];
    Runtime rt = Runtime.getRuntime();
                   double start = System.currentTimeMillis();
    Process proc = rt.exec(command, env, runDir);
    // Capture output in separate thread
    ThreadedStreamReader error = new ThreadedStreamReader(proc.getErrorStream(),
    "ERROR");
    ThreadedStreamReader output = new ThreadedStreamReader(proc.getInputStream(),
    "OUTPUT");
    error.start();
    output.start();
    exitVal = proc.waitFor();
    if (logger.isDebugEnabled()) {
         double runtime = (System.currentTimeMillis() - start) / 1000.0;
         logger.info("run " + runId + " " + command + " finished in " + runtime
    + " seconds");
    } catch (IOException e) {
    logger.fatal("DOE-2 failed \n" + e.getMessage());
    } catch (InterruptedException e) {
    e.printStackTrace();
    return exitVal;
    public static void main(String[] args) throws Exception, InterruptedException
    final Doe2MessageServer server = new Doe2MessageServer();
    while(!connected) {
    Thread.sleep(1000);
    logger.info("Attempting to start JMS service ...");
                   try {
              server.init();
                   } catch (Exception ex) {
    // shutdown hook to close JMS connection
    Runtime.getRuntime().addShutdownHook(
    new Thread() {
    public void run() {
    server.finalize();
    server.receiveMessage();

    Runtime.exec is a J2SE API. It's not really specific to WLS.
    You can read about it here:
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runtime.html
    It looks like you are starting a JMS Server in a separate process and
    that process is crashing.
    (You could of course just use WLS's JMS Server instead :>)
    -- Rob
    Iris Qu wrote:
    Rob,
    Thanks for your help.
    I asked a question about a weird Exception on Nov 14, and you told me that I am
    using Runtime.exec to start an external process, and that process is crashing.
    I am a green-hand on Weblogic, and I am trying to enhancing a project developped
    by another person, so I am not familiar with some concepts yet.
    Could you please give me some simple explanation about Runtime.exec and external
    process?
    I found two methods that uses "Runtime" from two classes as following, could you
    help me to see whether or not there is something wrong with the usage of Runtime?
    Thank you very much.
    private int runShellCommand(String command) {
    int exitVal = -1;
    try {
    File runDir = new File(runDirectory);
    String[] env = new String[0];
    Runtime rt = Runtime.getRuntime();
                   double start = System.currentTimeMillis();
    Process proc = rt.exec(command, env, runDir);
    // Capture output in separate thread
    ThreadedStreamReader error = new ThreadedStreamReader(proc.getErrorStream(),
    "ERROR");
    ThreadedStreamReader output = new ThreadedStreamReader(proc.getInputStream(),
    "OUTPUT");
    error.start();
    output.start();
    exitVal = proc.waitFor();
    if (logger.isDebugEnabled()) {
         double runtime = (System.currentTimeMillis() - start) / 1000.0;
         logger.info("run " + runId + " " + command + " finished in " + runtime
    + " seconds");
    } catch (IOException e) {
    logger.fatal("DOE-2 failed \n" + e.getMessage());
    } catch (InterruptedException e) {
    e.printStackTrace();
    return exitVal;
    public static void main(String[] args) throws Exception, InterruptedException
    final Doe2MessageServer server = new Doe2MessageServer();
    while(!connected) {
    Thread.sleep(1000);
    logger.info("Attempting to start JMS service ...");
                   try {
              server.init();
                   } catch (Exception ex) {
    // shutdown hook to close JMS connection
    Runtime.getRuntime().addShutdownHook(
    new Thread() {
    public void run() {
    server.finalize();
    server.receiveMessage();

  • Need info about Runtime.exec

    Hello, I have a non program specific question about how Runtime.exec works. First off assume that I handle all my input streams and output streams correctly, and I am not worried about inter process communication. The question is, when I use Runtime.getRuntime().exec(cmd[],pth[],dir) does the JVM that is running the code that calls it live until the spawned process dies, or can it die without waiting for the execed process to die? I am trying to write an app that can spawn a new copy of itself that is completely independent from the original process, and may live on long after the original is no longer needed. To ensure proper resource management I need to know that the JVM that launches the new process does not have to wait for the new process to die prior to completely cleaning itself up.
    Does that make sense?
    Any suggestions, ideas, questions?
    Thanks in advance for the help.
    Message was edited by:
    elixic

    Thank you all who gave useful input. I had done some reading on this already and could not find a definite answer on weather or not the calling JVM can properly dispose of itself prior to the process it called being disposed of.
    The answer it seems is dependent on context. In windows, and from a GUI app, it looks like the calling JVM can die any time it wants too. A command line app on the other hand seems to have to wait for the app it called to die first. I have not tested it on other OS's but I am sure it varies by OS as well. I would not even be surprised if it varies by JVM.
    So the short answer to my question that you all helped me find is this, It varies by context.
    Thanks again for the help.
    Isaac

  • Very very urgent! Please help about Runtime.exec on Solaris

    I wrote a software in Java.
    It contains a platform application and a variety of client applicaitons.
    Both use Swing MMI. I need my own JRE and invoke client from
    platform MMI. On Windows, the software run ok. But on Solaris,
    client are always blocked to do work.
    Whe run platform and client individually from command line,
    client will run ok too. While client is invoked by platform in programm,
    it will be blocked to run (client cannot recieve data from RS232).
    I noticed that client will continue to run once platform exits.
    So I really wonder whether there is something wrong with my codes
    to invoke client. Only Solaris invoking codes list here.
      public static boolean exec(String execStr) {
        Runtime runtime = Runtime.getRuntime();
        try {
          String[] args  = new String[] {
                "/bin/sh", "-c", execStr};
            Process p = runtime.exec(args);
            return true;
          return false;
         catch (Exception e) {
          e.printStackTrace();
        return false;
      }

    The execStr argment is
    /users/devConfig/jre/java -classpath "/users/devConfig/jre/lib:/users/devConfig/lib/ssop.jar:
    /users/devConfig/lib/zt103.jar..." zt.client.nsd200v.NSD200VApp ...Where /users/devConfig is my software installed directory, and /users/devConfig/jre is my own packaged JRE1.5.0.

  • How to make this works. it's about Runtime.exec().

    hi' i really need help about this.
    i have 2 class file. one named GoodWindowsExec that used to execute another file named maintest. (i post my code below). When i run GoodWindowsExec there's no problem but not working correctly.
    What i need is i can write something directly from my keyboard not via GoodWindowsExec file. So maintest can run normally just like when i execute it manual (java maintest from commandprompt) and display the output. If you look at the maintest file, this file need input from user. But why i can't doing this directly? How to implement this?
    This is java code that i need to execute (maintest) just for sample :
    public class maintest
         public static void main(String[] args)
              try
                   BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
                   System.out.print("Try input word : ");
                   String readInput = bfr.readLine();
                   /* String readInput = bfr.readLine(); i think this is the problem.
                    * If i remove this, GoodWindowsExec works fine.
                    * But i cannot remove it. This is my point.
                    * i want try to solve this */
                   System.out.println(readInput);
              catch(Exception e)
                   System.out.println(e);
    }This is my code (GoodWindowsExec) which used to execute maintest :
    public class GoodWindowsExec
         public GoodWindowsExec()
              try
                   String[] cmd = new String[]{"cmd.exe","/C","java","maintest"};
                Runtime rt = Runtime.getRuntime();
                   Process proc = rt.exec(cmd);
                   InputStream inStream = proc.getInputStream();
                   BufferedReader bfr = new BufferedReader(new InputStreamReader(inStream));
                   response res_in = new response(bfr);
                   InputStream errorStream = proc.getErrorStream();
                   BufferedReader errorBfr = new BufferedReader(new InputStreamReader(errorStream));
                   response res_err = new response(errorBfr);
                   res_in.start();
                   res_err.start();
                   OutputStream otStream = proc.getOutputStream();
                   DataOutputStream write = new DataOutputStream(otStream);
                   write.writeUTF("something");
                   /* write.writeUTF("something");
                    * i really don't know about this.
                    * if i declare this, the input not come from maintest / user directly.
                    * if i create some java editor application and want to execute some java code
                    * this is not right. cos input comes from this class not the execute class (maintest).
                    * How to make the input comes from user / execute class?
                   write.flush();
                   write.close();
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
              catch (Throwable t)
                 t.printStackTrace();
        public static void main(String args[])
              new GoodWindowsExec();
    class response extends Thread
         BufferedReader bfr;
         public response(BufferedReader bfr)
              this.bfr = bfr;
         public void run()
              try
                   String line = null;
                   while ( (line = bfr.readLine()) != null)
                             System.out.println(line);   
              catch (IOException ioe)
               ioe.printStackTrace(); 
    }Thank you very much...

    Hi' i think i have same problems with you. but now i think i got it after read this article. Thanks for both of you. specially sabre150.
    But i want to ask about this to sabre150. What if maintest try to request more than one input? How to handle it? and why Try input word : display at the second line? not the first line?
    i'm sorry if i modify this, but i change it like this :
    class outputer :
    public void run()
         try
              bfr = new BufferedReader(new InputStreamReader(System.in));
              String input = null;
              while ((input = bfr.readLine()) != null)
                   write.writeBytes(input);     
                   write.flush();
                   write.close();
         catch(Exception e)
              e.printStackTrace();
    }maintest :
    public class maintest
         public static void main(String[] args)
              try
                   BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
                   System.out.print("Try input word : ");
                   String readInput = bfr.readLine();
                   System.out.println(readInput);
                   System.out.print("Try input word again : ");
                   String readInput2 = bfr.readLine();
                   System.out.println(readInput2);
              catch(Exception e)
                   System.out.println(e);
    }When i execute i got this :
    test //request for first input
    Try input word : test
    Try input word again : null
    ExitValue: 0
    halo //request for second input
    java.io.IOException: The handle is invalid
         at java.io.FileOutputStream.writeBytes(Native Method)
         at java.io.FileOutputStream.write(Unknown Source)
         at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
         at java.io.BufferedOutputStream.flush(Unknown Source)
         at java.io.DataOutputStream.flush(Unknown Source)
         at outputer.run(GoodWindowsExec.java:78)Maybe you know the answer sabre150?
    Thanks...
    Message was edited by:
    2Puluh11Lapan3

  • About runtime.exec()

    hi friends,
    i'm unable to open vb exe file through java application.
    i'm tring with this code
    Process p = Runtime.getRuntime().exec("cmd /D:Program Files/Microsoft Visual Studio/VB98/socketappvb/");
    p.waitfor()
    that is the error in my code.
    thank is advance

    Your exec string doesn't look right. What the heck are those forward slashes? And why do you call cmd for an exe? (Can't say for sure, but I believe the cmd is only required to execute batch files.)

  • Help me ! about Runtime.exec()

    [php]
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.File;
         /** * Class for running external executable (extrnal process).*/
    public class ExeRunner{     
    /* Path to Dlls required by the executable */
    String path = "C:\\Program Files\\jdk1.4\\bin";
    public void run(String [] args) throws IOException, InterruptedException
    final Process p = Runtime.getRuntime().exec(args, new String [] {path});
    new Thread()
    public void run()
    try
    BufferedReader in = new BufferedReader (new InputStreamReader (p.getInputStream()));     
    String str = null;     
    while ((str = in.readLine()) != null )     
    System.out.println(str);     
    in.close();     
    catch (IOException e){      
    e.printStackTrace();     
    }.start();
    new Thread()
    public void run()
    try     {     
    BufferedReader in      = new BufferedReader (new InputStreamReader (p.getErrorStream()));     
    String str = null;     
    while ( (str = in.readLine()) != null )
    System.err.println(str);
    in.close();     
    catch (IOException e)
    {       e.printStackTrace();
    }.start();
    int exitCode = p.waitFor();          
    if ( exitCode != 0 )
    throw new IOException ("Executable "+args[0]+" stopped with error code "+exitCode);
    public static void main(String [] a) throws Exception
    String args [] = new String[4];
    args[0] = "C:\\Program Files\\jdk1.4\\bin\\java.exe";
    args[1] = "-classpath";
    args[2] ="E:\\Practical";
    args[3] ="HelloWorld";
    new ExeRunner().run(args);
    [php]

    I get the above from another forum. the program running well.
    however , my problem is that I want to it display another DOS console to print the "Hello World ".
    and the DOS console will not closed untill user close it.
    /* Path to Dlls required by the executable */
    String path = "C:\\Program Files\\jdk1.4\\bin";
    final Process p = Runtime.getRuntime().exec(args, new String [] {path});
    can you explain what the above line doing. and what is the "path" means?
    I also tried to change the codes in main method
    String args [] = new String[6];
    args[0] ="cmd.exe";
    args[1] ="/start";
    args[2] = "C:\\Program Files\\jdk1.4\\bin\\java.exe";
    args[3] = "-classpath";
    args[4] ="E:\\Practical";
    args[5] ="HelloWorld";
    new ExeRunner().run(args);
    But it does not work.
    Thanks very much!

  • Problem executing file through Runtime.exec

    Hi,
    i am trying to execute a java programem using the the following line
    Runtime.exec("java Myclass");
    But no response for it.
    Anybody help me.
    Jossy

    As required by forum protocol for people who ask questions about Runtime.exec I am posting the standard link:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to capture Runtime.exec() output? doesn't seem to work?

    This is the first time I've used Runtime.exec();
    Here's the code:
    Runtime rt = Runtime.getRuntime();
                process = rt.exec(jobCommand);
                BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line=null;
                while((line=input.readLine()) != null) {
                     System.out.println("OUTPUT: " + line);
                int exitVal = process.waitFor();
            } catch(Exception e) {
                 e.printStackTrace();
            }//end catchas you can see, this is just copied and pasted out of the standard example for this method.
    When it gets to the line:
    while((line=input.readLine()) != null)
    it doesn't read anything. However, when i run the SAME exact command from the windows CMD prompt i get a ton of output.
    what am i doing wrong here?
    thanks.

    Welcome to the forum!
    >
    as you can see, this is just copied and pasted out of the standard example for this method.
    >
    No one can see that - you didn't post a link to the example you said you copied.
    >
    it doesn't read anything. However, when i run the SAME exact command from the windows CMD prompt i get a ton of output.
    >
    No one can see what command you are talking about; you didn't post the commnd or even describe what output you expect to get.
    >
    what am i doing wrong here?
    >
    What you are doing wrong is not providing the code you are using, the command you are using or enough information about what exactly you are doing.
    No one can try to reproduce your problem based on what you posted.

  • Java's Runtime.exec() method

    When you shell out to java's Runtime.exec() method, are the process name and arguments the same for the child process that is spawned.
    We see duplicated processes about the time when our logs tell us this command was run. However, we cannot seem to reproduce this. Has anyone else seen anyone this before?

    That's what I though too. But check this out . . .
    Our code looks as follows:
    private Runtime rt;
    private Process p;
    rt = Rutime.getRuntime();
    p = rt.exec(command);
    This exec() call creates a new process, which is a child of the java process that runs this command. The final process looks like the "command" string that is passed to the exec() method call. In our case, the command is a call to the /usr/bin/mail utility to send out faxes and emails.
    We ran a very tight loop executing the rt.exec() call over and over. What we found was that for a minor fraction of a second, the newly created process looks just like the original process including the same arguments. However, the PID's indicated that one process was the child of the other. This is why it looked like we had 2 of the same processes. WILD!
    Thanks guys!

  • Runtime.exec() hangs on solaris 10, deadlock in soft_delete_session ?

    Hi,
    In my application sometimes Runtime.exec calls hangs for ever.
    The pstack of java process is at the end of the post. It seems like there is a deadlock in soft_delete_session.
    Does anyone know of any java/os patch we can apply to fix this issue?
    I will really appreciate any tips to get over this issue.
    # uname -a
    SunOS thor256 5.10 Generic_120011-14 sun4u sparc SUNW,Sun-Fire-V245
    # /opt/VRTSjre/jre1.5/bin/java -version
    java version "1.5.0_10"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
    Java HotSpot(TM) Server VM (build 1.5.0_10-b03, mixed mode)
    The trace is as follows:
    0xff340408 __lwp_park + 0x10
    0xff339068 mutex_lock_internal + 0x5d0
    0xfb08a2ec soft_delete_session + 0xf0
    0xfb089f90 soft_delete_all_sessions + 0x4c
    0xfb084348 finalize_common + 0x70
    0xfb0844d8 softtoken_fini + 0x44
    0xfb0d8d48 _fini + 0x4
    0xff3c00d0 call_fini + 0xc8
    0xff3ca614 remove_hdl + 0xab8
    0xff3c4d54 dlclose_intn + 0x98
    0xff3c4e68 dlclose + 0x5c
    0xfb3a2b3c pkcs11_slottable_delete + 0x138
    0xfb39d664 pkcs11_fini + 0x4c
    0xff2c0ea0 postforkchild_handler + 0x30
    0xff332c20 fork + 0x140
    0xfe8f8df4 Java_java_lang_UNIXProcess_forkAndExec + 0x7d4
    0xf9226020 0xf9226020 * java.lang.UNIXProcess.forkAndExec(byte[], byte[], int, byte[], int, byte[], boolean, java.io.FileDescriptor, java.io.FileDescriptor, java.io.FileDescriptor) bci:0 (Compiled frame; information may be imprecise)
    0xf92216c4 0xf92216c4 * java.lang.UNIXProcess.(byte[], byte[], int, byte[], int, byte[], boolean) bci:62 line:53 (Compiled frame)
    0xf90fa6b8 0xf90fa6b8 * java.lang.ProcessImpl.start(java.lang.String[], java.util.Map, java.lang.String, boolean) bci:182 line:65 (Compiled frame)
    0xf90fbe0c 0xf90fbe0c * java.lang.ProcessBuilder.start() bci:112 line:451 (Compiled frame)
    0xf921842c 0xf921842c * java.lang.Runtime.exec(java.lang.String[], java.lang.String[], java.io.File) bci:16 line:591 (Compiled frame)
    0xf9005874 * java.lang.Runtime.exec(java.lang.String[]) bci:4 line:464 (Interpreted frame)
    0xf9005874 * TestExec.run() bci:26 line:22 (Interpreted frame)
    0xf9005c2c * java.lang.Thread.run() bci:11 line:595 (Interpreted frame)
    0xf9000218
    0xfecdca88 void JavaCalls::call_helper(JavaValue*,methodHandle*,JavaCallArguments*,Thread*) + 0x5b8
    0xfecf4310 void JavaCalls::call_virtual(JavaValue*,Handle,KlassHandle,symbolHandle,symbolHandle ,Thread*) + 0x18c
    0xfecf416c void thread_entry(JavaThread*,Thread*) + 0x12c
    0xfecf3ff0 void JavaThread::run() + 0x1f4
    0xff02fb30 void*_start(void*) + 0x200
    0xff340368 lwpstart

    Found this information about this problem:
    Bug: http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6276483
    Info for patch 127111-11: http://sunsolve.sun.com/search/document.do?assetkey=1-21-127111-11-1
    Download page: http://sunsolve.sun.com/show.do?target=patches/zos-s10

  • Issue using Runtime.exec() in Vista

    I've coded a simple method using Runtime.exec() to get the client MAC ID , and it worked alright on XP. Now my client want to switch to vista , and the method is not working. Here's my code
    import java.io.*;
    import java.util.regex.*;
    public class GetMac
         public static String getMacAddress()
              String mac="";
              System.out.println("getMacAddress");
              try {
                   RunTimeExecutor re=new RunTimeExecutor("ipconfig /all");
                    mac=re.executeAndReturnMac();
                    re.destroy();
              } catch (Exception e) {
                   e.printStackTrace();
              return mac;
    import java.io.IOException;
    import java.io.InputStream;
    * @author amal
    public class RunTimeExecutor
              String cmd;
              Process proc;
               * @param cmd
              public RunTimeExecutor(String cmd)
                        this.cmd=cmd;
               * @return boolean
               * @throws WIException
              public  String executeAndReturnMac() throws Exception
                   System.out.println("run");
                   String mac="";
                        if(cmd==null)
                                  throw new Exception("No Commands");
                        try
                              final Runtime rt = Runtime.getRuntime();
                              proc = rt.exec(cmd);
                              final StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream());
                              InputStream iis=proc.getInputStream();
                              final StreamGobbler outputGobbler = new StreamGobbler(iis);
                              errorGobbler.start();
                              outputGobbler.start();
                              int exit=proc.waitFor();
                              System.out.println("exitVAl "+exit);
                              if(exit==0)
                                   mac=outputGobbler.MAC;
                              return (exit==0) ? mac :null;
                    catch (IOException e)
                              e.printStackTrace();
                    catch (InterruptedException e)
                              e.printStackTrace();
                    catch(Exception e)
                         e.printStackTrace();
                    return null;
              public void destroy()
                        if(proc!=null )
                                  proc.destroy();
    * @author amal
    import java.io.*;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    * @author amal
    public class StreamGobbler extends Thread
        InputStream is;
        OutputStream os;
        public String MAC;
        StreamGobbler(InputStream is)
            this(is,null);
        StreamGobbler(InputStream is,OutputStream redirectTo)
            this.is = is;
            this.os = redirectTo;
         * @see java.lang.Thread#run()
        public void run()
            try
                PrintWriter pw = null;
                if (os != null)
                    pw = new PrintWriter(os);
                InputStreamReader isr = new InputStreamReader(is);
                int c=0;
                BufferedReader br = new BufferedReader(isr);
                String line=null;
    System.out.println("Start Reading");
                     while ( (line = br.readLine()) != null)
                          System.out.println(line);
                         if (pw != null)
                             pw.println(line);
                         Pattern p = Pattern.compile(".*Physical Address.*: (.*)");
                            Matcher m = p.matcher(line);
                            if (m.matches())
                                 MAC = m.group(1);
                                 System.out.println("seting MAC to "+MAC);
                                 break;
                if (pw != null)
                    pw.flush();
            } catch (Exception e)
                e.printStackTrace(); 
    }The inputStream of the process doesnt get printed at all , the loop condition in StreamGobbler 'while ( (line = br.readLine()) != null)
    ' is never true.
    Also , in random cases i've seen the System.out.println("exitVAl "+exit); line executing before the System.out.println("Start Reading"); line , and i though proc.waitFor() would guarentee otherwise.

    thx guys for ur replies . The issue was because of some browser security system ( or so they said . ).However i'm still puzzled about the 'waiting for the stream to finish' part .
    paul.miner wrote:
    {I think the process is allowed to end with output still in the >>buffers, ..so this would be expected. You should be waiting for >>your .streams to finish, since that's what you really >>care .about. .Also, .you need to add synchronization between your >>threads so you can accurately retrieve "MAC". Also, do not break out >>of the loop when you find what you're looking for, you should >>continue .reading until the end of the stream.Wasn't I suppose to be reading out of the stream to prevent an overflow?Also the break is done there are multiple lines like 'Physical address .....: xxxxxxxxxx ' in the output , and the macid is the first one.About the ProcessBuilder , I'll look into it . Thx for your advice.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Set Path to DLLs for Runtime.exec(...)

    I have got a little server application that creates a Process of an external application. (eg Example1.exe or Example2.exe - which one is to be called is configurable via property files)
    All of these external apps rely on a couple of DLLs, that are distributed seperately from the ExampleX.exe.
    So my directory structure looks something like this:
    /Server (contains my java app)
    /Server/dll (contains the dlls)
    /Server/app (contains ExampleX.exe files)
    How do I configure my Runtime.exec(...) so that it can supply a PATH info to my DLLs?
    How about the ...exec(String command, String[] envp, File dir) call?
    -> It already works when the DLLs are in the same dir as my .exe files.
    -> I would like to avoid setting a global PATH to my DLLs in the OS.
    Has anybody already dug itself through this pile?

    Solved my problem, awarded the Dukes to myself! ;-)
    Here's what I did in case somebody else has similar probs:
    The envp Parameter didn't work for me. The Application and the DLLs were found but the Subprocess was somehow screwed up - the Threading didn't work right. (I have no clue how that could be, but whatever...)
    Anyway I could put the path to the DLLs in the PATH info of my startup script for the Java-Server. The subprocess inherits that information.
    I used relative path info there so that nobody has to fiddle around in the script when the application is moved to different directories.
    The only thing you have to do then is to set the present working directory of the subprocess to the location of the server via ...execute(String, String[], File)
    You need to supply thecomplete path to the application in the first String parameter that way but all in all this semms to be the most sensible way to do it.

  • Urgent Help Required : Java Runtime.exec

    Hello,
    We are using the java Runtime.exec in the AIX 4.3.3 environment. Java version 1.1.8. We are consuming the output of the Runtime.exec without using the threads. i.e we are doing a readline on the output stream of the runtime and printing it to th standard output in a loop. When this is over we take the error stream and do the same.
    We have two problems.
    1. A ksh that is run using the java Runtime.exec is showing up multiple processes with the same as a tree structurre when we do a ps.
    Why is this ?
    2. Also whatever we consume from the standard output/error of runtime and print it to system.out is not being output/error. Any pointers on this ?
    Thanks in advance,
    Raj.

    thanks !
    1. we have single thread executing the command. And there are no multiple processes spawned inside the shell script also.
    2. I am sorry about the phrasing. Eventhough we are catching the output stream and error stream and dumping the output correspondingly, the process ( the shell script ) hangs ! And this behaviour is sporadic. Please let us know why the process should hang !
    Thanks,
    rajesh.

  • Don't redirect output or Runtime.exec()

    Hello, I am using Runtime.exec() to execute a .bat file on a windows xp machine. I am able to read the output within the java app just fine. The problem is that I don't want the output to be redirected to a java stream as the default behavior of Runtime.exec() enforces. Is there anyway to run a .bat file and have the output stay in the DOS window that appears?

    Thanks for the input so far. Here is more detail. I have to execute the bat file. No way around that one. I tried getting no window to pop up but the only solution I found to this was to create a shortcut and launch the process with a minimized window. Not to keen on this solution as it isn't very elegant. Plus it would be very very bad if the window was closed in the middle of execution. If anybody knows of a better way not to have the window show up I would like to hear it.
    So now I am stuck with a blank DOS window. I figure the next best thing is to just use the window and have the output that normally shows up there to actually show up there when launched from a java process. This way hopefully the user realizes something is running in the window and they shouldn't close it.
    You would think java would have some way to a launch a process and forget about it.

Maybe you are looking for

  • Error with windows live messenger

    I tried to update msn messenger yesterday! and since then msn has gone from my phone and in My world the app just says starting download! but has been doing that for 24hrs. Ive had no problems downloading anything else. I cant do anything with it eit

  • Recent Problem Scanning with a Canon Lide 600F

    Hello, I'm using Acrobat v10.1.9 on a Windows 7 64Bits OS and with a Canon 600F Scanner (latest drivers installed). During few weeks after a fresh installed I was able to use my Canon with Acrobat X. The scanner was recognized and I was able to put s

  • Renew Skype Number

    I have problem in renew skype number , i need to change payment method from skype credit to Visa , but the selection not found , when i click changr payment method i find only skype credit only  what i can doing to renew my skype number by Visa  My R

  • Can't download some podcasts

    My iTunes 8 can't download CBS Evening News and CNN Video podcasts. But it does work with ABC News Video. I'm wondering what makes the difference.

  • Success, Please?

    Dear Fellow Macintosh Lover, I realize that the mood of Discussion Boards is negative, for these serve as places to tell grievances.  Just as I would expect, the boards about Mavericks are downers.  Happy users of Mavericks remain quiet.  So - Please