Runtime.exec(), linux and redirection

Hi all,
I need to exec an external command from java under linux, and have both the stderr and stdout of the command redirected to the
stdout, so that I can capture them and keep them in synch in the java app. I've tried many combination, but I'm unable to make
this work: only the standard output shows up. Note that I can make this work under windows.
A java code example and a small C example to simulate the program to be invoked follows. Running the java program should show both the "messsage" and the "error" lines, but it shows only the "message" ones.
Note that removing the apparently redoundant ">&1" doesn't solve the problem. I got a suggestion to modify the exec invocation into
String[] cmd = { "/bin/sh", "-c", "./test1 >&1 2>&1" };
  Process p = Runtime.getRuntime().exec(cmd); but that didn't work eiter.
Can anyone tell me where I'm wrong?
Roberto
======================= class test.java ================================================
import java.io.*;
public class test {
  public static void main(String args[]) {
    new test();
  public test() {
    try {
      Process p = Runtime.getRuntime().exec("/bin/sh -c ./test1 >&1 2>&1")
      InputStream inStr = p.getInputStream();
      BufferedReader inBr = new BufferedReader(new InputStreamReader(inStr));
      String line;
      while((line = inBr.readLine()) != null) {
        System.out.println("line = "+line);
      try {
        p.waitFor();
      } catch(InterruptedException ex) {}
      System.out.println("process terminated with code = "+p.exitValue());
      inBr.close();
    }catch(IOException ex) {
      System.out.println("IOException : "+ex.getMessage ());
}======================= end of class test.java ================================================
======================= test1 program ================================================
#include <stdio.h>
int main(int argc, char **argv) {
  int i;
  for(i=0; i<100; i++) {
    fprintf(stdout, "message %d\n", i);
    fprintf(stderr, "error %d\n", i);
}======================= end of test1 program ================================================

Redirection dosen't work with Runtime.exec(), it really dosen't have sense. Do the foolowing:
String[] cmd = { "/bin/sh", "-c", "./test1" };
Process p = Runtime.getRuntime().exec(cmd);
OutputStream out = p.getOutputStream();
//now wrte out to the file, formating as you want
What is doene obove is execute your command, without redirection, and the obtaininh the output stream of the created process. This is "the place" where the process will write everithig it'll would write in the console if executed there.
The handle the OutputStream as any other OutputStream, and write it to the HD or do whtever you want.
Abraham.

Similar Messages

  • Best way to close a Runtime.exec() process and how to handle closing it?

    I have multiple Runtime.exec() Processes running and am wondering what the best way it is to close them and take care of closing the resources. I see that Process.destroy() seems to be the way to terminate the Process - is finalize() the best way to close anything in that Process?
    Thanks

    I was involved with your other thread, so I think I know what you are trying to do.
    All Dr's answers are correct.
    Now you have a program A written by you that does Runtime.exec() of multiple instances
    of another program B written by you. You want A to somehow tell B to exit.
    You must use some kind of Inter Process Communication. If this is the only interraction
    between the two programs I can suggest two options. If you anticipate more
    interraction, you may want to look at other means (RMI, for instance, which was proposed
    by EJP in the other thread for starting B, is also useful in exchanging info).
    Solution 1:
    Start a thread in B and read stdin. A will write to stdin a command, such as QUIT.
    When B reads it, it does System.exit().
    Solution 2:
    Start a SocketServer in B that accepts connections on a separate thread.
    When A wants B to exit, it connects to it and writes a command such as QUIT.
    When B reads it, it does System.exit().
    You may note that QUIT is not the only command you can send from A to B, in case you will need more.
    Edited by: baftos on Nov 5, 2007 2:15 PM

  • Runtime.exec(), unix and Mac's ipfw

    Hi community,
    I have two questions:
    1. I am writing a java application that is to call a unix script, and I've tried using the runtime code:
    try{
    Process proc = Runtime.getRuntime().exec(hello);
    catch(Exception e){}
    The code seems to not be calling the unix script. Is there something wrong with the code or does my script need to be in a certain file format?
    2. I'm a Mac user and the script contains ipfw firewall rule sets. By simply calling a unix script with a change of firewall rule sets in Terminal, will that actually do any changes to the rule set? The purpose of the java app is to be able to change firewall rules depending on condition.
    All help is greatly appreciated.

    tomcassidy wrote:
    1. I am writing a java application that is to call a unix script, and I've tried using the runtime code:
    try{
    Process proc = Runtime.getRuntime().exec(hello);
    catch(Exception e){}
    The code seems to not be calling the unix script. Is there something wrong with the code or does my script need to be in a certain file format?Wouldn't you call it with "sh hello" or somesuch?

  • Runtime.exec() crashes JVM

    I wrote a program that runs a Perl script repeatedly via Runtime.exec().
    Q: Under what circumstances would this procedure silently crash the JVM? I am experiencing this behavior on Linux using Sun's JDK as well as IBM's. There is no error output. The program simply exits. What is causing this? And, how can it be avoided? If there is a way to recover from whatever problem is occurring, that would be ideal.

    Thanks jschell! Your input is helpful.
    I suspect that case #4 is in play here. When I run my program with the "-Xrs" switch, "Terminated" is outputted just before the JVM exits. Is there any way to intercept the signal to terminate from the child process before the JVM exits?
    NOTE: I am not running Runtime.exec() concurrently and I am explicitly destroying each Process after process.waitFor(). Also, I tend to watch the linux "top" output to confirm that only one Perl process is running at a time. I have tried various versions of a "runCommand" method. The current version spawns no additional threads:
    public static int runCommand(String[] command) throws InterruptedException, IOException
              ProcessBuilder builder = new ProcessBuilder(command);
              builder.redirectErrorStream(true);
              Process process = builder.start();
              InputStream input = null;
              InputStream error = null;
              OutputStream output = null;
              BufferedReader reader;
              String line;
              try     {
                   input = process.getInputStream();
                   error = process.getErrorStream();
                   output = process.getOutputStream();
                   reader = new BufferedReader(new InputStreamReader(input));
                   while ((line = reader.readLine()) != null)
                        System.out.println(line);
                   return process.waitFor();
              finally
                   close(output);
                   close(error);
                   close(input);
                   process.destroy();
              }

  • Make can't recursively call Make when run from Runtime.exec (for some user)

    This one is a little complicated. The afflicted platform is Mac OS X. It works fine on Linux, it seems, and even then, it does work for some Mac OS X users...
    First, the setup. I have a Java program that has to call GNU Make. Then, GNU Make will recursively call Make in some subdirectories. This results in the following Java code:
    String make = "make"; //on windows, I have this swapped with "mingw32-make"
    String workDir = ...; //this is programmatically detected to be the same folder that the parent Makefile is in
    Runtime.getRuntime().exec(make,null,workDir);This calls make on a Makefile which has the following line early on to be executed (this is only a snippet from the makefile):
    cd subdirectory && $(MAKE)When I fetch the output from the make command, I usually get what I expect: It cd's to the directory and it recursively calls make and everything goes smoothly.
    However, for one particular user, using Mac OS X, he has reported the following output:
    cd subdirectory && make
    /bin/sh: make: command not found
    make: *** [PROJNAME] Error 127Which is like, kinda hurts my head... make can't find make, apparently.
    I've gotten some suggestions that it might be due to the "cd" command acting wonky. I've gotten other suggestions that it may be some strange setup with the env variables (My Mac developer is implementing a fix/workaround for 'environ', which is apparently posix standard, but Mac (Mr. Posix Compliance...) doesn't implement it. When he finishes that, I'll know whether it worked or not, but I get the feeling it won't fix this problem, since it's intended for another area of code entirely...
    Also worth mentioning, when the user calls "make" from the terminal in said directory, it recurses fine, getting past that particular line. (Later on down the road he hits errors with environ, which is what my aforementioned Mac dev is working on). Although calling "make" by hand is not an ideal solution here.
    Anyways, I'm looking for someone who's fairly knowledgeable with Runtime.exec() to suggest some way to work around this, or at least to find out that perhaps one of the User's settings are wonked up and they can just fix it and have this working... that'd be great too.
    -IsmAvatar

    YoungWinston
    YoungWinston wrote:
    IsmAvatar wrote:
    However, for one particular user, using Mac OS X, he has reported the following output:One particular user, or all users on Mac OS?In this case, I have two mac users. One is reporting that all works fine. The other is reporting this problem.
    cd subdirectory && make
    /bin/sh: make: command not found
    make: *** [PROJNAME] Error 127Which is like, kinda hurts my head... make can't find make, apparently.If that is being reported on the command line, then I'd say that make wasn't being found at all.If make isn't being found, then who's interpreting the Makefile?
    It's also just possible that the make script on Mac isn't correctly exporting its PATH variable, though it seems unlikely, since this would surely have been reported as a bug long ago.
    I've gotten some suggestions that it might be due to the "cd" command acting wonky...Also seems unlikely. 'cd' has been around since shortly after the K-T extinction event.
    WinstonBy "acting wonky", I mean being given a bad work directory or some such, such that it's not changing to the intended directory.
    Andrew Thompson
    Andrew Thompson wrote:
    (shudder) Read and implement all the recommendations of "When Runtime.exec() won't" (http://www.javaworld.com/jw-12-2000/jw-1229-traps.html).
    Already read it. I already know the dreadful wonders of Runtime.exec. But in this case, it's been working fine for us up until one Mac user reported that make can't find make.
    Also, why are you still coding for Java 1.4? If you are not, use a ProcessBuilder, which takes a small part of the pain out of dealing with processes.Usually I do use a ProcessBuilder. I noticed that it usually delegates to Runtime.exec() anyways, and seeing as I didn't need any of the additional functionality, I decided to just use Runtime.exec() in this particular case.
    jschell
    jschell wrote:
    So print thos env vars, in your app and when the user does it.I'll look into that. It's a good start.
    -IsmAvatar

  • BufferedReader blocks when using Runtime.exec()

    I'm executing an external process in Linux (RH 8.0) using the Runtime.exec() method and then setup two threads to read the standard and error output of the process. Most of the time this works great but every now and then the readers block and the process never exit. I even tried seting up a timer task that will close the BufferedReader after 20 seconds but that's not enough to unblock the reader - the external process is a dummy shell script which for now just outputs a single line. Does anybody have any idea why that would happen? Any help would be appreciated!
    Cheers,
    /Francis
    P.S. Here's a snippet of the code:
    public class ProcessRunner {
      private Process _process = null;
      private StreamGobbler _errorGobbler = null;
      private StreamGobbler _outputGobbler = null;
      private String[] _commandArgs;
      public ProcessRunner(String[] args) {
        _commandArgs = args;
      public int runCommand()
        throws IOException {
        int exitCode = -1;
        _process = Runtime.getRuntime().exec(_commandArgs[0]);
        // start up stream gobblers (inspired from javaworld)
        _outputGobbler = new StreamGobbler(new BufferedReader(new InputStreamReader(_process.getInputStream())));
        _outputGobbler.setDaemon(true);
        _errorGobbler = new StreamGobbler(new BufferedReader(new InputStreamReader(_process.getErrorStream())));
        _errorGobbler.setDaemon(true);
        _outputGobbler.start();
        _errorGobbler.start();
        try {
          exitCode = _process.waitFor(); // *** THIS NEVER RETURNS ***
          if (_outputGobbler != null) {
            _outputGobbler.join();
          if (_errorGobbler != null) {
            _errorGobbler.join();
        } catch (InterruptedException exc) {
          //ok, continue
        return exitCode;
      class StreamGobbler extends Thread {
        BufferedReader reader;
        StreamGobbler(BufferedReader reader) {
          this.reader = reader;
        public void run() {
          try {
            final int buffersize = 256;
            byte[] bytes = new byte[buffersize];
            String line = null;
            while((line = reader.readLine()) != null) {    // ***THIS ALSO BLOCKS ***
              baos.write(line.getBytes(), 0, line.length());
          } catch (IOException ioe) {
            // Do something here
          } finally {
            reader.close();
            reader = null;

    I use this type of thing in my code using JDK1.3.1. Only difference is I don't use set up the readers in threads. I suspect you have a thread deadlock, but I can't see why. Do you have to have the i/o stream readers in the thread?

  • How to display Runtime.exec() command line output via swing

    Hi all, I'm new to java but have a pretty good understanding of it. I'm just not familiar with all the different classes. I'm having trouble capturing the output from a command I'm running from my program. I'm using Runtime.exec(cmdarray) and I'm trying to display the output/results to a JFrame. Once I get the output to display in a JFrame, I'd like it to be almost like a java command prompt where I can type into it incase the command requires user interaction.
    The command executes fine, but I just don't know how to get the results of the command when executed. The command is executed when I click a JButton, which I'd like to then open a JFrame, Popup window or something to display the command results while allowing user interaction.
    Any examples would be appreciated.
    Thank you for your help in advance and I apologize if I'm not clear.

    You can get the standard output of the program with Process.getInputStream. (It's output from the process, but input to your program.)
    This assumes of course that the program you're running is a console program that reads/writes to standard input/output.
    In fact, you really should read from standard output and standard error from the process you start, even if you're not planning to use them. Read this:
    When Runtime Exec Won't

  • Executing bat file without using Runtime.exec()??

    Hi all
    From my java App ,I am running a bat file. This is what I did:
    When I press 'execute' button inside my App, it runs a bat file through Runtime.exec() method. Since exec() runs it through cmd.exe, get a DOS window when I press Execute button. If I manually runs my app from command promt , I dont get it. But I have to create a short cut of my main class in the desktop. This is happening when I run my app from desktop icon.
    Now I want to eleminate DOS popup everytime I press execute button. Would anyone pls give an idea how to run bat file without using Runtime.exec()? Any suggestion will be helpful.
    Thanks

    jscell
    Thanks for taking time to answer to my problem .
    Here is what my problem: I create a shortcut of my main class in the desktop. Through this shortcut ,I run my java App. My App has a execute button, When I press this button , It run another bat file through Runtime.exec() method, and show some result in the result PAnel. NOw what happen , I get a DOS command window , everytime I press execute button. , Which is very annoying . But If I run my App thorugh command promt by executing: "java myApp", then I dont get this DOS popup. But I have to create a shortcut in the desktop, so other can use it conveniently.
    NOw I am not sure why I am getting this DOS window in the middle of my Application. IS it for using Runtime.exec() method? or for running bat file through my application? Can anyone pls tell me? I am kind of new to java, and I am learning lot of stuff from this forum .
    Would u pls suggest me about how to eleminate this DOS popup when I press execute button.
    Regrds

  • Runtime.exec output lost when executing ftp.

    I'm writing application, which can execute command line scripts.
    I'm executing Runtime.exec("cmd") and then writing commands into output stream. I'm continously reading from input and error stream, so that's not the case.
    Everything goes fine while I'm executing simple commands, like: dir, cd.
    The problem begins when I try to execute more sophisticated commands, like ftp.
    Here is the scenario:
    ftp server_nameFtp asks for user name
    userAfter providing user name, the output is lost. There are no more characters in InputStream ever. The application doesn't hangs, because ftp actually performs next commands (password, cd, get file). It is just output that isn't shown.
    Is it known problem or am I doing something wrong?
    Please, help.

    I post some code:
    import java.util.*;
    import java.io.*;
    class StreamGobbler extends Thread
        InputStream is;
        String type;
        char[] buf = new char[1000];
        StreamGobbler(InputStream is, String type)
            this.is = is;
            this.type = type;
        public void run()
            try
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                boolean write = false;
                while (true) {
                     StringBuffer buffer = new StringBuffer();
                     while (br.ready()) {
                          int chars = br.read(buf, 0, 1000);
                          buffer.append(buf, 0 ,chars);
                          write = true;
                     if (write) {
                          System.out.print(type + ">" + buffer.toString());
                          System.out.flush();
                          write = false;
                    try {
                             Thread.sleep(1000);
                        } catch (InterruptedException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    class StreamForward extends Thread
        InputStream is;
        OutputStream os;
        StreamForward(InputStream is, OutputStream os)
            this.is = is;
            this.os = os;
        public void run()
            try
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                OutputStreamWriter wr = new OutputStreamWriter(os);
                String line=null;
                while ( (line = br.readLine()) != null) {
                    wr.write(line+"\n");
                    wr.flush();
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    public class GoodWindowsExec
        public static void main(String args[])
            try
                String osName = System.getProperty("os.name" );
                String cmd = new String();
                System.out.println("OS: "+osName);
                if( osName.equals( "Windows NT" ) || osName.equals("Windows XP"))
                    cmd = "cmd.exe" ;
                else if( osName.equals( "Windows 95" ) )
                    cmd = "command.com" ;
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd);
                Process proc = rt.exec(cmd);
                // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERROR");           
                // any output?
                StreamGobbler outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUTPUT");
                StreamForward forward = new
                     StreamForward(System.in, proc.getOutputStream());
                // kick them off
                errorGobbler.start();
                outputGobbler.start();
                forward.start();
                // any error???
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
            } catch (Throwable t)
                t.printStackTrace();
    }This is example code, which demonstrate this problem.
    It creates new cmd process and forwards to it standard input. Process output and error streams are displayed on standard output.
    Basically you can execute dos commands by entering them from keyboard.
    Try:
    dir
    cd something
    etc.
    Now, to show a problem try:
    ftp your_favorite_server
    The program should ask for username. Enter username. Nothing is displayed. Notice that ftp is still running and executing commands, but doesn't display any output.
    Any clue, why this is happening?

  • Runtime.exec() does not work under Linux

    Hi,
    I have a generic application runner class that runs an external
    program and redirects stdout/stderr to a buffer/file.
    While everythings works just fine under Windows, I get the
    following exception under Linux trying to run the Java interpreter
    'java':
    java.io.IOException: "/usr/lib/SunJava2-1.3.1/jre/bin/java": not found
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:139)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:546)
    at java.lang.Runtime.exec(Runtime.java:413)
    I have checked that the file /usr/lib/SunJava2-1.3.1/jre/bin/java
    exists.
    Any help appreciated!
    Marc

    can I ask how you solved it? I am having a problem
    with quotes just now to and it might help me!I simply tested what the current platform is and
    only used quotes under Windows.
    Marc

  • Can't redirect the Runtime exec output

    I'm trying to get mysqldump to give me some output which I can redirect to the tmp1 location
                   String tmp2 = "mysqldump";
                   Runtime rt1 = Runtime.getRuntime();
                   if(File.separatorChar == '\\') {
                        tmp2 = "\"C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump\"";
                   tmp1 = tmp2 + " > " + tmp1;
                   rt1.exec(tmp1);All I want to see at this point is just the error message telling me how to use mysqldump.
    After that I'll do something useful.
    I'm running under NetBeans and if I don't try to redirect I get nothing in the output window.
    Of course, if I run it from a Command box, I see the expected output.
    I know I'm running the program because if I change it to the nonsense mysqldump3, it will tell me that it can't find the file.
    I can't figure out where the output is going and how to capture it.
    Any ideas would be appreciated.
    Ilan

    Ilan wrote:
    Hi Sabre,
    Since I didn't understand your code, I'll use it as a chance to learn something.
    I don't understand what cmd.exe is doing. It is just opening a DOS box?No! It is interpreting the command string.
    Why do you need that? (Maybe I do and I don't know so....)You need to learn a good bit more about your operating system. Get a good book on Windows.
    >
    The simplest thing would be String command = "mysqldump > file.sql".
    Why shouldn't that work?1) Because the directory containing your mysqldump is not in the PATH.
    2) Because the redirection operator '>' is only applicable when interpreted by the command processor (cmd.exe). Reads your Windows manual.
    >
    The reason I need the explicit path is because mysqldump isn't on my Windows path (Linux is nicer that it is in usr/bin, so there is no problem.)
    So I detect Windows and for Windows put the path and command in quotes.
    (Now that I think about it, cmd.exe probably wouldn't work in Linux anyway.)On Linux you will need your shell to interpret the redirection operator '>' .
    >
    What is that "/C" all about? Go to drive c:?
    Your first attempt looks like a confusion with mysqldump, once without a path followed by a path.
    That one I don't understand at all.
    How do I go about getting control of the stderr, if I don't already have control?
    BTW, I haven't yet tried it in Linux. First I'll get the Windows version going.
    Thanks for your reply. I'll try to learn from it.You need to read, read again, study and then implement the recommendations in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
    Sorry if this sounds like I'm passing the buck but your lack of knowledge of Windows, Linux and Runtime.exec() means I cannot help without writing a large tutorial.

  • How to make Runtime.exec call Linux exec?

    Howdy,
    I am trying to use a combination of 'find' and 'rm' to delete all files with a certain extension in a directory and all of its subdirs.
    Here's the command:
    Process proc = runtime.exec("find " + dir + " -name '*.vcs' -exec rm -rf {} \\;");
    It's failing, not sure why, the exitCode is 1 instead of 0. I'm not sure if it's because I have to escape the '\' character, or if it's because I am calling Linux's 'exec' function within a Java exec() call, or something else entirely.
    The easiest thing to do would be to just use rm, but that doesn't seem to be an option. With rm it seems to be all or nothing -- If I try:
    rm -rf *.vcs
    it fails if it doesn't find a file with that extension in the start directory (even though I've specified -r). But if I enter:
    rm -rf *
    it nukes my directories AND files, something I don't want to happen. I realize this is a Linux thing, I'm just explaining it here as background, just in case.
    Anyway, so is there a way to do this? Perhaps with another system call, without using Linux's exec()?
    Many thanks
    Bob

    import java.io.*;
    public class ExecutingALinuxCommand
        static class PipeInputStreamToOutputStream implements Runnable
            PipeInputStreamToOutputStream(InputStream is, OutputStream os)
                is_ = is;
                os_ = os;
            public void run()
                try
                    byte[] buffer = new byte[1024];
                    for(int count = 0; (count = is_.read(buffer)) >= 0;)
                        os_.write(buffer, 0, count);
                catch (IOException e)
                    e.printStackTrace();
            private final InputStream is_;
            private final OutputStream os_;
        public static void main(String[] args)
            try
                String dir = System.getProperty("user.home") + "/work/dev";
                String[] command = {"sh","-c", "find " + dir + " -name '*.java' -exec grep -l Runtime {} \\;"};
                final Process process = Runtime.getRuntime().exec(command);
                new Thread(new PipeInputStreamToOutputStream(process.getInputStream(), System.out)).start();
                new Thread(new PipeInputStreamToOutputStream(process.getErrorStream(), System.err)).start();
                int returnCode = process.waitFor();
                System.out.println("Return code = " + returnCode);
            catch (Exception e)
                e.printStackTrace();
    }

  • Using redirection operator ( ) in Runtime.exec()

    I am trying to execute a command "cat abc.txt > 123.log" from my Java program using Runtime.exec(). However, the exec() command isnt able to interpret ">" as an operator, instead it uses this as a string. Any suggestions on how I can run the above command using exec()???

    hi hiwa,
    could u tell me, why dont this
    e, why dont this program is not clearing the screen
    in linux. though some commands are working like
    "poweroff", "reboot"..
    public class ExecuteCommand{
    public static void main(String[] args) throws
    ws Exception{
    String[] cmd = {"sh","-c","clear"};
    //String cmd = "clear";
    Runtime rt = Runtime.getRuntime();
    rt.exec(cmd);
    Commands like "poweroff" and "reboot" work on underlying system while "clear", "cd" etc.
    work on current shell. Current shell is the shell on which we have invoked java command.
    But the shell java runtime invokes is not(can't be) current shell but its child, a sub-process.
    Thus we don't see current shell window cleared by a java runtime program.

  • Performance issue Runtime. exec("cp folder1 folder") in Linux,Weblogic.

    Using Runtime. exec() copying files from folder1 to folder2 using cp command in Linux. It will take each file copy 2 sec if we use web logic 10.3 and jrocket. if we run in Linux without web logic it takes only 0.013 sec. why it takes more time to load cp command with web logic.
    Environment
    Weblogic 10.3
    Linux 5.2
    Jrocket 1.6

    A 64 bit VM is not necessarily faster than a 32 bit one. I remember at least on suggestion that it could be slower.
    Make sure you use the -server option.
    As a guess IBM isn't necessarily a slouch when it comes to Java. It might simply be that their VM was faster. Could have used a different dom library as well.
    Could be an environment problem of course.
    Profiling the application and the machine as well might provide information.

  • 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