Runtime.exec() won't work

Hi all,
i've got a program that i want to via a java program,
in ms-dos, the programma is called by:
mace2 -n9 -p -m10 -c <puzzle.in> puzzle.outBut in my java program if I use:
Process mace = Runtime.getRuntime().exec("mace2 -n9 -p -m10 -c <puzzle.in> puzzle.out");the program gets called, but never ends properly, and the java
program halts.
Anything wrong? Thanks in advance.

You can't read, write and run in the same thread - this was tested using the group example and -n4; using -n9 would take a long time.
import java.io.*;
class Piper implements Runnable {
  InputStream in;
  OutputStream out;
  Piper (InputStream in, OutputStream out) {
    this.in = new BufferedInputStream(in);
    this.out = new BufferedOutputStream(out);
  public void run () {
    try {
      try {
        try {
          for (int i; (i = in.read()) != -1; ) {
            out.write((byte)i);
        } finally {
          in.close();
        out.flush();
      } finally {
        out.close();
    } catch (IOException ex) {
      ex.printStackTrace();
public class CallMace {
  static final String pathToMace = "<whatever>\Otter33-Win32\\bin\\";
  static void runMace (String inFile, String outFile) {
    try {
      Process p = Runtime.getRuntime().exec(pathToMace + "mace2 -n9 -p -m10 -c");
      Thread tIn = new Thread(new Piper(new FileInputStream(inFile), p.getOutputStream()));
      Thread tOut = new Thread(new Piper(p.getInputStream(), new FileOutputStream(outFile)));
      tIn.start();                              
      tOut.start();                              
      p.waitFor();
      tIn.join();
      tOut.join();
    } catch (Exception ex) {
      ex.printStackTrace();
  public static void main (String...args) {
    runMace(args[0], args[1]);
}Pete

Similar Messages

  • Runtime.exec ignores the working directory argument

    Hi Folks,
    I need to run a batch file in a particular directory, from a Java program.
    Here, I want to run "startMySQL.bat" from the ./bin directory.
    I used the following code to do so.
         String commandToExecute = "startMySQL.bat";
         File file = new File("bin");
    Process sqlPrcs = Runtime.getRuntime().exec(commandToExecute, null, file);     
    When I run these lines in a program, I get the following exception:
    java.io.IOException: CreateProcess: startMySQL.bat error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Unknown Source)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at com.aperto.ems.packetmax.AuthenticationScreen.startDB(AuthenticationScreen.java:603)
    at com.aperto.ems.packetmax.AuthenticationScreen.validateUserAndReinitialize(AuthenticationScreen.java:479)
    at com.aperto.ems.packetmax.AuthenticationScreen.access$0(AuthenticationScreen.java:468)
    at com.aperto.ems.packetmax.AuthenticationScreen$OnOKButtonPress.actionPerformed(AuthenticationScreen.java:628)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener$ReleasedAction.actionPerformed(Unknown Source)
    at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    at javax.swing.JComponent.processKeyBinding(Unknown Source)
    at javax.swing.JComponent.processKeyBindings(Unknown Source)
    at javax.swing.JComponent.processKeyEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    "error=2" in Windows mean "not able to find the file".
    Any clues on how I can run the batch file from a particular working directory?
    Thanks!

    Hi,
    I changed the code to print the user.dir output and the absolute path of the file. It looks like this:
    String commandToExecute = "startMySQL.bat";
    File fl = new File("bin");
    System.out.println(fl.getAbsolutePath());
    System.out.println(System.getProperty("user.dir"));
    Process sqlPrcs = Runtime.getRuntime().exec(commandToExecute, null, fl);
    Below is the output I get:
    C:\Program Files\Aperto\WaveCenter\Back-End_Server_2.0_build8\bin
    C:\Program Files\Aperto\WaveCenter\Back-End_Server_2.0_build8
    java.io.IOException: CreateProcess: startMySQL.bat error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Unknown Source)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at com.aperto.ems.packetmax.AuthenticationScreen.startDB(AuthenticationScreen.java:604)
    at com.aperto.ems.packetmax.AuthenticationScreen.validateUserAndReinitialize(AuthenticationScreen.java:479)
    at com.aperto.ems.packetmax.AuthenticationScreen.access$0(AuthenticationScreen.java:468)
    at com.aperto.ems.packetmax.AuthenticationScreen$OnOKButtonPress.actionPerformed(AuthenticationScreen.java:629)
    I assure you, "startMySQL.bat" is there under "bin"
    Thanks,
    Sandeep

  • 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

  • Runtime.exec does not work for commands with lengthy outputs

    I need to use Runtime.exec to run some custom commands on a Unix box. I have been doing this for quite some time now and had begun to feel comfortable when recently I started facing a problem. The thing is, whenever there is a command which prints a lot of data on to the console, the program is not able to exit from the waitFor method. Is there some thing that can be done about this?
    Following is a part of the code I use:
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec (command);
    System.out.println ("Got the process");
    int exitValue = p.waitFor();
    System.out.println ("Exit value: " + exitValue);When the output of the "command" is lengthy, it hangs after printing "Got the process".
    PS: By lengthy output, I mean that the command results in printing lines to the console which might be more than 100 in number. Say, something like what "ls -R /" would do in Unix / Linux.

    From java.lang.Process API doc:
    The Runtime.exec methods may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
    So you need to consume the process' output. Check the StreamGobbler example from this article.
    Hope it helps.

  • Runtim exec() method not working.....giving Exception

    whts the code to use exec() method. i m using it as follows and also catching exception.
    Runtime r=Runtime.getRuntime();
    Process p=r.exec("java A");
    code is giving IOException at runtime with error=2.

    Here is an example I used when I first needed to test the runtime.exec
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class TestRuntime {
        public static void main(String args[])
            try
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("java A");
                InputStream stderr = proc.getErrorStream();
                InputStreamReader isr = new InputStreamReader(stderr);
                BufferedReader br = new BufferedReader(isr);
                String line = null;
                System.out.println("<ERROR>");
                while ( (line = br.readLine()) != null)
                    System.out.println(line);
                System.out.println("</ERROR>");
                int exitVal = proc.waitFor();
                System.out.println("Process exitValue: " + exitVal);
            } catch (Throwable t)
                t.printStackTrace();
    }Are you waiting for the process to end before exiting your program?

  • Runtime.exec() does not work normally

    I try to wrapper the oracle connect command on unix using this function:
    runtime.exec("sqlplus username/password@dbinstance")
    it is ok on windows, but on unix, after runing the class, I get nothing. what is the problem?
    Please help me. thanks

    There are several traps with runtime.exec(). The most important one is that you should read
    the output stream of the launched program. Otherwise it will stop running when the console buffer overflows. The size of the buffer differs for various OSes.
    Look at this article:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    It it does not answer your problem, try to search the forums:
    http://search.java.sun.com/Search/java?qt=%2B%22exec%22+-%22Replies%3A+0%22&col=javafrm&rf=0&qp=%2Bforum%3A31
    This problem has been asked hundreds of times.
    Hope, this helps.

  • Runtime.exec() does not work?

    I'm trying to invoke a C++ executable from java using the Runtime.exec() method. The C++ application accepts a filename as a command line argument & opens the file. This C++ app is unicode enabled i.e. it can accept UTF-16 (wide char) parameters. Howevere, when i invoke this application using Java's Runtime.exec() and specify a japanese file name as an argument, the japanese characters get converted to '?' characters by the time they are received in the C++ application. I'm running this application on Windows 2K, default i.e. English version.
    Looking at the source code of Runtime class, it seems that the exec()
    function makes use of a native helper function - execInternal(). Does
    this function support the entire unicode range?
    Is there any way we can avoid the conversion of japanese characters to '?' characters? Also, is there any other alternative for invoking an external application with Unicode (Say, japanese) arguments?
    Please reply ASAP.
    Thanks!

    >
    I'm trying to invoke a C++ executable from java using
    the Runtime.exec() method. The C++ application accepts
    a filename as a command line argument & opens the
    file. This C++ app is unicode enabled i.e. it can
    accept UTF-16 (wide char) parameters. Howevere, when i
    invoke this application using Java's Runtime.exec()
    and specify a japanese file name as an argument, the
    japanese characters get converted to '?' characters by
    the time they are received in the C++ application. I'm
    running this application on Windows 2K, default i.e.
    English version.
    Looking at the source code of Runtime class, it seems
    that the exec()
    function makes use of a native helper function -
    execInternal(). Does
    this function support the entire unicode range?I don't know because I've never tested this case specifically.
    You didn't show your code though. How are you reading in the String? You mentioned that you passed a Japanese character String as a filename argument. I also read that you are running on an English Win2K platform. How did you read that argument in? It may just be that you read the argument in your default encoding(English) and you needed to specify an alternate one.

  • Runtime exec() Problem, change working dir

    Hi!
    I have following problem:
    I want to call an executable from my home-directory under Linux this way:
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec("/home/tom/prog/exec-command");
    Unfortunately I'm getting either exception "file not found" (but it's there) or no complain but no program run...
    perhaps something's wrong with the path-name?
    If I call the program in the directory with a shell it works fine.
    Would be very happy if anybody can give a hint!
    Thanks a lot,
    Manuel

    You are interested in the programs output? Does it write to stdout or stderr or both? In any case, my advice is to go multithreading and use one thread to wait for the program to exit, one to read stdout and one to read stderr. If you just use one thread for reading, the program might block. I normally use something like this:
      final int BUFFER = 2048;
      final Process p = Runtime.getRuntime().exec(args);
      //read standard out output of the external executable
      //in seperate thread to avoid I/O deadlocks
      new Thread()
        public void run()
           try
             BufferedInputStream in =  new BufferedInputStream (p.getInputStream());
             int i;
             byte[] buf = new byte[BUFFER];
             while ( (i = in.read(buf, 0, BUFFER)) != -1 )
                System.out.write(buf, 0, i);
             in.close();
           catch (IOException e)
             e.printStackTrace();
      }.start();
      //read standard error output of the external executable
      //in seperate thread for symmetry
      new Thread()
        public void run()
           try
             BufferedInputStream in =  new BufferedInputStream (p.getErrorStream());
             int i;
             byte[] buf = new byte[BUFFER];
             while ( (i = in.read(buf, 0, BUFFER)) != -1 )
                System.err.write(buf, 0, i);
             in.close();
           catch (IOException e)
             e.printStackTrace();
      }.start();
      //Wait for the external process to finish     
      int exitCode = p.waitFor();          
      if ( exitCode != 0 )
        throw new IOException("Executable stopped with error code "+exitCode); Cheers, HJK

  • Runtime.exec() doesn't work

    Hi all,
    I have got the following piece of code, I just don't understand why I don't receive any email after I have run
    the program.
    public class Test {
      public static void main(String[]args) {
        Runtime.getRuntime().exec("mailx -s [email protected] < input.txt");
    // where input.txt is a text file..
    I know if I want to, I can you JavaMail API to make it work, but I try to avoid if I can.. please advise me..
    Thanks
    Regards,
    Thinh

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    You need to execute a shell interpreter or manually feed the process's stdin from the file.

  • Any ideas why Runtime.exec() w/ 1.4.0 works but doesn't w/ 1.4.1

    I have developed a program which uses Runtime.exec(). It works in development but not in the production.
    The development machine runs Windows2000 with SDK 1.4.0.
    This program does not run on the target machine (production). The target machine is a Windows2000 servers with JRE 1.4.1_01.
    Here is the error:
    java.io.IOException: CreateProcess:
    "C:\Program Files\2TIFF\2TIFF.EXE"
    "s=C:\SplitTiff\pet.tif"
    "d=D:\SplitTiffWork"
    -namegen=123456.tif
    -sep
    -ct3
    error=3
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Unknown Source)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at utility.splitTiff.SplitTiff.extract(SplitTiff.java:54)
    at utility.splitTiff.SplitTiff.main(SplitTiff.java:340)
    The six lines following "Create Process:" are the elements of the String[] parm of Runtime.exec().
    Error 3 was returned by the JRE.
    Does anyone have any suggestions what is going on?
    Thanks much! I've got some Dukes to give out for some help on this.
    Bill Blalock

    Thanks!
    Where can I find out the meaning of errors returned by Runtime.exec()?
    Please reply to
    http://forum.java.sun.com/thread.jsp?forum=54&thread=291993
    And I'll send a couple a Duke I have locked up over there your way.
    Have a good weekend!!!

  • Runtime.exec lifecycle

    I am trying to execute a client using the following code below. It works fine when i run as stand alone java program. I am familiar with the javaworld article "When Runtime.exec() won't" ...
    Process p = Runtime.getRuntime().exec("\"c:\a b\\client.exe\" "\"some param\"""); //   "c:\a b\client.exe" "some param"
                InputStream in = p.getInputStream();
                InputStream err = p.getErrorStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String line = null;
                while ((line = br.readLine()) != null) {           }
                in.close();            br.close();
                br = new BufferedReader(new InputStreamReader(err));
                while ((line = br.readLine()) != null) {            }
                p.destroy();But when I incorporate it to a web application using jrun it crashes in windows, shows the debug dialog. I don't get any exceptions.
    Any clues?

    As has already been pointed out, you do need to follow the recommendations in the 'traps' article but you seem to have ignored two of them.
    First, you don't read stdout and stderr in separate threads. You can use the control thread to read one of them and a separate thread to read the other. Even better, if your really don't care about the content of stdout and stderr then use ProcessBuilder and redirect stderr to stdout and read stdout as you currently do.
    Second, you don't wait for the process to terminate. Even worse, you destroy() it! Don't do this. This is possibly why the process crashes! Always wait for the process to complete and always check the exit code.
    Now not part of the 'traps' article but a bit of advice - when debugging a Runtime.exec() problem or a ProcessBuilder problem ALWAYS write the stdout and stderr out somewhere. It is a very very very useful bit of diagnostic information.

  • 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

  • T2K/T5K type of Solaris servers and Runtime.exec

    It is being consistently observed that on T2k/T5k type of Solaris servers (e.g. T5220), the UNIX commands sent from Java using the Runtime class APIs are not being reveived by Solaris. It does not happen always, only occasionally. But when it happens, the java process hang at process.waitFor(). We are using Java1.6.
    I read the Java World article "When Runtime.exec() won't" and the behavior we are seeing is not because of any of the known pitfalls mentioned in the article. Also the warning in the Runtime API that speaks about the limited buffer size is also not applicable in this case because we do see it working sometimes. All of a sudden Runtime.exec gets stuck. We have also observed that the problem is not dependent on the command we pass through the Runtime.exec API. It happens for any trivial command.
    For more information on the issue, when we execute a 'pstack' on the process id, we see the following output most of the time and the 'truss' output shows the java process to be in a sleeping state:
    # pstack 20650
    ff2c52d8 lwp_park (0, 0, 0)
    ff2bf350 cond_wait_queue (24dd90, 24dd78, 0, 0, 0, 0) + 28
    ff2bf770 cond_wait_common (24dd90, 24dd78, 0, 0, 0, 0) + 294
    ff2bf874 cond_wait (24dd90, 24dd78, 0, 0, 0, 0) + 10
    ff2bf8b0 pthread_cond_wait (24dd90, 24dd78, ff2f3700, 0, f337da00, ecf00000) + 8
    eedddacc kernel_delete_session (24dd60, 24dd58, 0, 1, 3, 1c63c) + 114
    eeddd7dc kernel_delete_all_sessions (0, 1, 0, 1c8b4, 0, eedfa000) + 98
    eedd1eb4 cleanup_library (0, 1, 0, eedfa000, 28180, 3) + 3c
    eedd1f1c kernel_fini (0, 1, 0, eedfa000, 28120, eedfa4a4) + 44
    eede89e0 _fini (ff3f40fc, ff3f5a70, 2b3f4, 0, ff3f4910, 821) + 4
    ff3c54b4 call_fini (ff3f40fc, f43518f0, eede89dc, ff3f42f0, ff3f42a8, ff3f4910) + cc
    ff3cfdc0 remove_hdl (f43518f0, f1c4e2bc, 0, 4000, ff300a54, 4821) + ac8
    ff3ca408 dlclose_intn (f4351978, ff3f4910, ff3f40fc, 2a520, ff3ca4bc, 0) + 24
    ff3ca4e8 dlclose (f4351978, 0, f4350b88, 0, 1c00, 1) + 24
    eee33904 pkcs11_slottable_delete (1, f9e2c0, 46ec90, eee46bb0, 0, 1) + 138
    eee2e42c pkcs11_fini (eee46b8c, 1, eee2e074, eee46000, 17c18, eee46b84) + 4c
    ff241f38 postforkchild_handler (1d18, ff2f3700, 1c00, 4, f337da00, ff2f3700) + 30
    ff2b74bc fork (0, 41, 0, f1c4e744, ff2f3700, f337da00) + 144
    fe8a8ee4 Java_java_lang_UNIXProcess_forkAndExec (ffffffff, 0, fee0c0, fe8c4000, 4, 2) + 6d0
    f940bc20 * java/lang/UNIXProcess.forkAndExec([B[BI[BI[BZLjava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;)I+-20552
    f940bbc4 * java/lang/UNIXProcess.forkAndExec([B[BI[BI[BZLjava/io/FileDescriptor;Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;)I+0
    f94058b8 * java/lang/UNIXProcess.<init>([B[BI[BI[BZ)V+62
    f9405764 * java/lang/ProcessImpl.start([Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Z)Ljava/lang/Process;+182
    f9405874 * java/lang/ProcessBuilder.start()Ljava/lang/Process;+112
    f9405874 * java/lang/Runtime.exec([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;+16                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    If you haven't found the answer yet, I found it in another article. Basically, * and other wildcards are expanded by the shell so Runtime.getRuntime()exec("ls /tmp/*") won't work. You need to use the String[ ] form of exec(), i.e. Runtime.getRuntime()exec( new String[ ] {"sh", "-c", "ls /tmp/*"} )
    hope that helps.

  • Runtime.exec() and apostrophe?

    Hi there,
    I try to execute a Unix program using Runtime.exec(). This works as long as I don't need any apostrophe characters:
    works: <path>/<program> <someArguments>doesn't work: <path>/<program> <someArguments> -ls='rm /tmp/test.xml'In the latter case, I get an error message stating a syntax error.
    But when I enter exactly the same command directly into the shell, I don't get an error. Instead, the desired behavior occurs.
    Note: The parameter "-ls" lets the program execute a command once certain criteria are met. But the command in question is not part of the problem. For example, -ls=ll works...
    Thanks in advance for your help! :-)
    btw.: I've already read the "When Runtime.exec() won't" document, so I'm quite sure I didn't run into the shown pitfalls. Well, it could be related to the "Runtime.exec() is not a command line" section, but I haven't been able to figure out how to correct it.
    Kind regards,
    Dennis

    I guess you can remove the test for the SunOS operating system
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.lang.Runtime;
    import java.lang.Process;
    import java.lang.InterruptedException;
    import java.util.StringTokenizer;
    public class JExec {
         private static int lastExitValue = 0;
         public static int getLastExitValue() {
              return lastExitValue;
        public static final String osName= System.getProperty("os.name");
        public static byte[] execUNIXcmd(String commande, byte[] outputData, boolean closeStream) throws NullPointerException {
              Runtime runtime = Runtime.getRuntime();
              Process process = null;
              InputStream inputStream = null;
              OutputStream outputStream = null;
              byte[] bBuf = null;
              String tmpStr = null;
              if (!osName.equals("SunOS")) {
                   System.err.println("Unsupported Operating System");
                   throw new NullPointerException();
              } else {
                   // Dans le cas de SunOs
                   try {
                        process = runtime.exec(commande);
                        outputStream = process.getOutputStream();
                        inputStream = process.getInputStream();
                        if (outputData != null) {
                             outputStream.write(outputData);
                        if (closeStream) outputStream.close();
                        process.waitFor();
                        lastExitValue = process.exitValue();
                        bBuf = new byte[inputStream.available()];
                        inputStream.read(bBuf, 0, inputStream.available());
                        if (!closeStream) outputStream.close();
                        inputStream.close();
                        return bBuf;
                   } catch (InterruptedException e) {
                        System.err.println("ERROR ("+osName+"): Enable to wait the process");
                        throw new NullPointerException();
                   } catch (IOException e) {
                        System.err.println("ERROR ("+osName+"): Enable to read input lines");
                        System.err.println("->"+e.getMessage());
                        throw new NullPointerException();
         public static void main (String[] s) {
              String commande = "echo '$PATH'";
              System.out.println(new String(JExec.execUNIXcmd("sh -e", commande.getBytes(), true)));
    }

  • Java Runtime.exec running java problem

    Hi, I have a simple server application, which I would like to run in the background. The following line works for me:
    Runtime.getRuntime().exec("cmd /c start java -jar ..\\server\\server.jar -Dlog4j.configuration=file:src\\test\\resources\\log4j.properties -filename src\\test\\resources\\server.properties");But it displays the cmd window and I am unable to destroy it. So I would like to use
    Runtime.getRuntime().exec("java -jar ..\\server\\server.jar -Dlog4j.configuration=file:src\\test\\resources\\log4j.properties -filename src\\test\\resources\\serverIntegration.properties");But it simply doesn't connect to the server. That means, it starts some java process in the background, but my client fails to communicate (i dont know whether the server doesnt respond or the client fails to send the message, but still, with the cmd /c start it works). So why is that?
    A related question. How do I end the process? It is a server that "doesn't end". So I have to kill it and I would assume, that running the java only command would be capable to be destroyed, but with the cmd I have no luck there. I have already tried full paths and the overload of exec with String[] params.

    Read [_When Runtime.exec() won't_|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html].
    One reason why your server doesn't run is that it might be writing stuff to stdout (a.k.a System.out). And if your process doesn't read the newly created process' stdout, then that other process will block until something is read (which will be never).
    Read all of the pages of that article and follow its suggestions.

Maybe you are looking for

  • Different GL Account for WRX - based on Valuation Class (No Material Master

    Hi Gurus, My scenario is as given below. 1. We do not have any Material Master. We create short text PO's with account assignment category "P". 2. We are also using Material Group in our PO. We have one Material Group for Domestic Purchases (say M1)

  • Changing the Header in a Hybrid Web Container app on BlackBerry

    Hello Experts! I am trying to add a custom header to Hybrid Web Container Apps on SUP 2.0.  It would be nice to add branding or additional text - even the ability to center the text would be nice.  I have tried various jQuery approaches and can see t

  • Flash components+VB isssue

    Hi, I am doing a project which involves flah UI ,XML and VB. The UI has two major Tree Compnents,One menu bar and a few Accordions. All of these are populated with XML. Now this is embedded in a VB application. The Flash swf will send data to the VB

  • How can I make OPAC in Oracle Forms Builder

    Hello everyone, I'm developing a Library Management System as my project in my Oracle subject. Can anyone tell me how to make OPAC module of Library management system in Oracle forms builder. I don't have any idea because this is my first encounter i

  • Iterate through string column of data that is a varchar2 (2000)

    Hi, My question is how to iterate through the data by selecting the first 120 bytes of the column writing that to a UTL_FILE, then selecting the next 120 bytes to write that to the UTL_FILE as well until there is no more data. I am having a problem g