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.

Similar Messages

  • Setting up for Ant 1.6 with Weblogic 8.1 for Runtime.exec()

    Hello all,
    I'm trying to invoke my Ant script using Runtime.exec() but I run into the following exception:
    java.lang.InstantiationException
    Here's my script:
    set ANT_HOME=c:\apache-ant-1.6.1
    %ANT_HOME%\bin\ant %1 %2 %3 %4 %5 %6 %7
    My line of code in Java is the following:
    Runtime.getRuntime().exec("cmd /C build.cmd");
    When I modified my ant script to check the version of ant, I saw it was 1.5.3, not 1.6. I need 1.6 because I'm using certain 1.6 specific ant tasks in my build.xml.
    Does anyone have any idea?

    use WLS 8.1 SP3

  • Problem in setting path and classpath for java in RedHat linux 9

    Hi ,
    i am not able to set the PATH and CLASSPATH for j2sdk1.4.2_06
    I have tried with export PATH=$PATH:/usr/j2sdk1.4.2_06/bin
    and export CLASSPATH=$CLASSPATH:/usr/j2sdk1.4.2_06/lib
    in terminal
    but i want to configure it as permenant way for the jre and jdk
    and we should only type java or javac according to the requirement
    regards mihir...

    type those in .bashrc ... save and exit
    then at prompt, type 'source .bashrc'
    this is the permanent solution ...
    bhalo thakun

  • StdIn, stdOut, stdErr for Runtime.exec()

    I have searched through 100s of forum messages regarding this topic, but none have helped me enough.
    I have an application, app_A, that allows the user to select a database and other environment settings and then run an application using the selected settings. Running app_A on Windows 2000 using a Shortcut with the command: java.exe app_A automatically opens a dos window to write stdOut and stdErr (this is good). From within app_A I do the following:
    Runtime rt = Runtime.getRuntime();
    rt.exec("java.exp app_B");
    app_B, starts up just fine, except that I do not see the stdOut or stdErr from app_B.
    Questions:
    1. Where is it going and how can I get it?
    2. Is there way app_B can have it's own stdOut & stdErr, so the dos window for app_A can be suppressed (it is not really needed)?
    many thanks for help and direction
    Brent

    http://www.apl.jhu.edu/~hall/CWP-Sources/CWP-Examples/Chapter8/Exec/Exec.html may be this class of Marty Hall can be usefull for you.

  • HELP needed for Runtime.exec

    Here is the code. I'm able to compile it but the code doesn't FTP the file.
    String xfer = "g:/java/code/xfer.txt";
    String xferout="g:/java/code/xferout.txt";
    String[] ftpCommand={"ftp"," -n"," -s:" + xfer + " >" + xferout};
    Process processOutput = null;
    //String homeDir="c:/java";
    //File xferScript=new File(homeDir,xfer);
    PrintWriter xferScript=new PrintWriter(
    new BufferedWriter(
    new FileWriter(xfer)));
    xferScript.println("open " + downloadServer);
    xferScript.println("user " + loginId + " " + password);
    //xferScript.println("lcd " + homeDir);
    xferScript.println("prompt");
    xferScript.println("ascii");
    xferScript.println(method_mget + " " + FileToDownload);
    xferScript.println("dir");
    xferScript.println("bye");
    xferScript.flush();
    xferScript.close();
    Runtime process = Runtime.getRuntime();
    processOutput = process.exec(ftpCommand);

    This should fix it:     String xfer = "g:/java/code/xfer.txt";
         String xferout="g:/java/code/xferout.txt";
         String[] ftpCommand={"ftp"," -n"," -s:" + xfer);
         Process processOutput = null;
         PrintWriter xferScript=new PrintWriter(
              new BufferedWriter(
              new FileWriter(xfer)));
         xferScript.println("open " + downloadServer);
         xferScript.println(loginId);
         xferScript.println(password);          
         xferScript.println("prompt");
         xferScript.println("ascii");
         xferScript.println(method_mget + " " + FileToDownload+" "+xferout);
         xferScript.println("dir");
         xferScript.println("bye");
         xferScript.flush();
         xferScript.close();
         try {
              Runtime process = Runtime.getRuntime();
              processOutput = process.exec(ftpCommand);      
         catch (IOException ioe) {
              System.out.println("I/O error has occurred");
         ioe.printStackTrace();
         }Mark

  • Runtime.exec(command)

    hi experts,
    I am trying to execute a set of commands from java program
    eg: from command prompt
    java CommandExecutor c:\winnt\notepad.exe c:\some.exe c:\onemorecommand.exe
    and inside the CommandExecutor main method..
    public static void main(String []arg)
    for(i = 0; i < arg.length; i++)
    Runtime.getRuntime().exec(arg(i));
    the above code is executing all the command one after the other, but I want to execute the above commands squentially, i.e I want to execute the second command only after finishing the first command and the third after finishing the second and so on depending upon the arguments passed, how can I acheive this...
    I have tried to use the Process which is returned by the exec(arg) method but the exitValue() returns same value before execution and after execution.
    thanks,
    krishna

    This is the code I use for this very purpose and it works great. Here you go:
    * Wrapper for Runtime.exec
    * No console output is generated for the command executed.
    * Use <code>process.getOutputStream()</code> to write data out that will be used as
    * input to the process. Don't forget to include <code>\n</code> <code>\r</code>
    * characters the process is expecting.
    * Use <code>process.getInputStream</code> to get the data the process squirts out to
    * stdout.
    * It is recommended to wrap this call into a seperate thread as to not lock up the
    * main AWT event processing thread. (generally seperate threads are needed for both
    * the STDOUT and STDIN to avoid deadlock)
    * @param theCommand fully qualified #.exe or *.com command for windows etc.
    * @see   exec, shell, command, cmd, forDOS, forNT
    public static Process exec( String theCommand, boolean wait )
         Process process;
         try
              process = Runtime.getRuntime().exec( theCommand );
         catch ( IOException theException )
              return null;
         if ( wait )
              try
                   process.waitFor();
              catch ( InterruptedException theInterruptedException )
         return process;
    }

  • Runtime exec problem with command "start"

    L.S,
    I'm working on a webservice client for uploading
    and downloading files. When a file is downloaded, it
    should be opened by the appropriate application. I
    know that this is -in theory- possible by issuing a
    start command through Runtime.getRuntime.exec():
    public void doSomething(String realName, DataHandler handler) {
      File outFile = new File(realName);
      FileOutputStream out = new FileOutputStream(outFile);
      handler.writeTo(out);
      out.close();
      String fileName = outFile.getAbsolutePath();
      Process p = Runtime.getRuntime().exec("start " + fileName);
    }Running this on my Win2000 system with J2RE 1.4.2 consistently
    fails with this message:
    java.io.IOException: CreateProcess: start C:\tmp\test.pdf error=2When I issue the exact same command from a DOS shell, Adobe
    starts up with the test document loaded. I now believe that my own
    application is somehow 'holding on to' the file, preventing an
    external application like Adobe from consuming the same file.
    Does anyone know how I can get around a problem like this? How do
    I start the appropriate application and feed it the file that was
    just downloaded by the user?

    I did a search for Runtime.exec and found some good help in this forum. Someone posted something like the following and it works pretty well.
    <<begin code>
    // Determine proper shell command (extend per OS)
    String os_name = System.getProperty("os.name");
    String shellParam "";
    if (os_name.startsWith("Windows"))
    if ( (System.getProperty("os.name").endsWith("NT")) ||
    (System.getProperty("os.name").endsWith("2000")) ||
    (System.getProperty("os.name").endsWith("XP")) )
    shell = "cmd.exe";
    } else
    shell = "command.com";
    shellParam = "/C";
    // Create a string with your program executable
    String command = "myprogram.exe";
    // Create an array of each command, I found that placing "cmd.exe /c"
    // in the same string doesn't work.
    String[] cmd_array = new String[] {
    shell,
    shellParam,
    command
    Runtime.getRuntime().exec( cmd_array );
    <<end code>>
    Do a java API search for Runtime.exec (if you use Eclipse right click and hit Open Declaration) there are ways to invoke exec that support setting of the environment as well as the current directory.

  • Runtime.exec error - java.lang.NullPointerException

    Hi,
    I am trying out the example code from javaWorld that shows how to use exec to execute external command. The problem is that I aways run into java.lang.NullPointerException on line that has "Process proc = rt.exec(cmd);" I have tried to run the code under Windows XP and Windows 2003; and I get the same error message. Any idea on what might be casing this?
    Thanks,
    // GoodWindowsExec.java
    import java.util.*;
    import java.io.*;
    class StreamGobbler extends Thread
    InputStream is;
    String type;
    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;
    while ( (line = br.readLine()) != null)
    System.out.println(type + ">" + line);
    } catch (IOException ioe)
    ioe.printStackTrace();
    public class GoodWindowsExec
    public static void main(String args[])
    if (args.length < 1)
    System.out.println("USAGE: java GoodWindowsExec <cmd>");
    System.exit(1);
    try
    String osName = System.getProperty("os.name" );
    String[] cmd = new String[3];
    if( osName.equals( "Windows NT" ) )
    cmd[0] = "cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
    else if( osName.equals( "Windows 95" ) )
    cmd[0] = "command.com" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
    Runtime rt = Runtime.getRuntime();
    System.out.println("Execing " + cmd[0] + " " + cmd[1]
    + " " + cmd[2]);
    Process proc = rt.exec(cmd);
    // any error message?
    StreamGobbler errorGobbler = new
    StreamGobbler(proc.getErrorStream(), "ERROR");
    // any output?
    StreamGobbler outputGobbler = new
    StreamGobbler(proc.getInputStream(), "OUTPUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    } catch (Throwable t)
    t.printStackTrace();
    }

    What is System.getProperty("os.name") returning when you run on Windows XP or 2003?
    You are only filling in your cmd array when os.name is either Windows NT or Windows 95. In other cases, the elements of cmd are left as null.
    The documentation for Runtime.exec() says you will get a NullPointerException when elements of the array are null:
    http://apidoc.org/view/10563?a=exec%28java.lang.String%5B%5D%29

  • Runtime.exec() fails to run "javac" with "*.java" as arguments

    Hello,
    I am observing that Runtime.exec() consistently fails to execute "javac" when the Java files to be compiled are specified as "*.java". It fails with the following error:
    javac: file not found: /home/engine931/*.java
    Usage: javac <options> <source files>
    The same command used for Runtime.exec() runs fine from a the command shell. Is this is known problem with the Runtime class on UNIX, because it works fine on Windows.
    Any advise is appreciated.
    Thanks,
    Ranjit

    Your shell is expanding the command when you run javac from the shell. Try constructing your Runtime parameters so that your shell is executed, which then executes javac.
    The specific behavior is entirely dependent on the command interpreter that's used.

  • PATH Setting using Runtime.exec() on a UNIX env?

    Hi,
    How do we set the PATH using Runtime.exec() on a UNIX Env?
    I've tried the 'export' command and 'setenv' command but it throws an exception saying 'export' and 'setenv' not found.
    objProcess = Runtime.getRuntime().exec("setenv PATH /opt/ibm/java2-x86_64-50/bin");+
    Please suggest.
    Thanks,
    Tanu

    Your experimenting with the stuff could shed light on the question, whether the outcome is influenced by the relying of the started process on elements of the starting environment other than PATH.
    String[] envp=new String[1];
    envp[0]="PATH=/jdk1.5/bin";
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec("java Test",envp);

  • Executing DLLs from Java using JNI vs Runtime.exec()

    I am trying to understand the best way to execute a dll using java. The dll I am testing with takes a few input parameter. If I use JNI with System.loadLibrary("dll"); what do I need to do to pass the arguements in as well? Can I just add the arguements in the java code like private int xyz = "value"; and expect that the dll will accept them or is there special definitions I have to set up in the dll to make it work?
    Alternatively I was looking at using Runtime to execute the dll by using Runtime.exec("dll param1 param2",env,filePath); Does anyone know if there are drawback to doing it this way vs. using JNI or is this just as efficient? Any help would be appreciated.

    You seem to be confused...
    "execute a dll using java"
    Unless I'm mistaken, a dll is not executable. A dll is a library of code. This code has (hopefully) some well-defined entry points (declared in a header file somewhere) which you must call in a C/C++ file. The arguments you pass to the dll will come from java through JNI.
    As far as your understanding of this entire process, it is obviously confused beyond the scope of a simple reply. I recommend you read the examples and ALL of the documentation available here:
    http://java.sun.com/docs/books/tutorial/native1.1/index.html
    When you get the/an example running (or just set up to run) then post your code and comments here for more help.
    Ian

  • Runtime.exec and setting environment variables

    Runtime.exec and setting environment variables
    I need a decent example which works on Windows.
    Got any?

    Thank you.
    I was hoping for an example of the use of
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runti
    e.html#exec(java.lang.String,%20java.lang.String[]) or
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runti
    e.html#exec(java.lang.String,%20java.lang.String[],%20j
    va.io.File) which take environment variable
    information such as PATH.
    The reason is because there is a library which is
    being loaded via loadLibrary (
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Syste
    .html#loadLibrary(java.lang.String) ). However, for
    the child process to find the library the PATH needs
    to be updated.
    Any example regarding changing the PATH variable via
    Java so that libraries can be loaded and processes
    created? (Perhaps, I should make a new post and
    restate the question with this more explicit
    information?)
    That won't work. LoadLibrary occurs in the JVM environment. As I said you can't change the JVM environment via exec().
    If the shared library needs something in the path then you are going to have to set the path before your application starts up.
    If you just need to load the library from someplace that is not on the path then you should be using System.load().

  • How to give path in Runtime. exec( )

    Hi,
    I am trying to create an user interface, in which, it should open a different file (for example, example.doc)when a button is clicked in the applet. let us say, the path for example.doc is "C:\\WINDOWS\\DeskTOP\\folder1".
    I tried with the following code
    Runtime.getRuntime().exec("C:\\WINDOWS\\Desktop\\folder1\\example.doc");
    but, when I click on the button it is not opening example file and I am getting an exception. I am using Runtime.exec() command for the first time.Anybody can help me with this???

    Since when was a document an executable? The main problem is many people think Runtime.exec () is the same thing as the command line. The answer is, it's not. Typing "example.doc" in the windows terminal emulator (also known as cmd.exe in Windows 2000/XP or command.com in others) will work because example.doc is opened with the application configured to open files with the ".doc" extension.
    However, files ending with ".doc" are not executables. If you wish to open a ".doc" file with the associated application, try this: Runtime.getRuntime ().exec ("cmd /c example.doc"); Not that I don't know if this will work with command.com as I haven't tried, but it should work with cmd.exe without problems.
    Hope it helps.
    Cheers

  • 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

  • Runtime.exec and ServerSocket for IPC...blocking problems

    I have built an IDE for assembling/deploying web applications.
    I am supporting a 'test' mode in the IDE where a compiled 'solution/application' is executed in a separate vm from the IDE using Runtime.exec. For the whole sandbox thing. Don't want a wayward application crashing my IDE.
    Naturally I want a way to communicate start/stop from the IDE to the running application. So sockets are my only choice. Calling process.destroy from my IDE won't invoke a shutdownhandler in the generated application's vm, and I want an orderly shutdown as the generated applications open resources/etc.
    When I execute the generated application from within the IDE the thread code that creates a server socket blocks in the ServerSocket constructor...why?
    When I execute the solution using 'java' outside of my IDE, I can set up a server socket and all works fine.
    My IDE is NEVER creating server sockets waiting for client connects...only the generated application does this. So it isn't a case of the IDE already listening for requests on the same port as the server/generated application.
    Proving the above is that I can manually start my generated application, start my ide, then invoke the menuitem from the IDE that writes a 'close' byte to the client's socket...and the running application DOES shut down.
    Any ideas?

    I have decided on a different approach.
    At first I thought...ok I have the ServerSocket on the wrong 'side'. I then put the ServerSocket code in the always-running IDE and the Socket code on the running/exec'd application. But still a hang on the running application when constructing the Socket.
    I decided instead to call Process.destroy on the running app.
    Given that generated app is running in a separate vm, when it shuts down via process.destroy from the ide...although vm shutdown hooks aren't called...I guess it's ok since a destroy of the vm will release all resources. Not as clean as I'd like though.
    Additionally, I cannot determine 'true' start of application as no socket notification can be done. I merely determine start after a Runtime.exec of jvm process. Subsequent errors in startup will merely be determined by the IDE in process.waitFor or process.exitValue.
    I was getting a wierd socket error when attempting my prior solutions...and not a lot on the web regarding this subject...all relevant posts seemed to be in German/from Germany. Odd. Would need my wife to translate! Mein gott!
    I guess I could've communicated from ide to Runtime.exec'd application via a generated file in filesystem...but this seemed cheesy. Sockets should've been used for ipc between java vms...or so I thought.

Maybe you are looking for

  • Recently updated ITUNES, cannot open it now, Please help

    I updated Itunes last night. Now it will not open when I click on it. I have uninstalled it and reinstalled with the same results. Any ideas?

  • How to use left-justified with Move command??

    Hi, I have a field BKPF-XBLNR which I have to download to an final output table. I am using the command "Move"... Move T_BKPF-XBLNR to T_OUTPUT-XBLNR. My problem is that for some records this field is a combination of characters and numbers ... but s

  • Configuration of text file to excel file

    How to post data from text file to excel file. this means sender side i have text file here fields are separated by commas, that data take and put in the MS-Excel sheet format, here the pages are like boxes, how to put data in that boxes.

  • Flexible environment import & export?

    Dear Community, is it possible to export and import environments. I would use a new MIDI mapping to play in drum notes with some doubled keyboard notes to trigger one Drum instrument (e.g. Drum Designers hihat receives f#1 from keyboard notes f#1 and

  • Flex 4.6 : ViewNavigatorApplication for i-Phone Getting slow navigation

    Hi, I had created ViewNavigatorApplication for i-Phone in Flex (Flash Builder 4.6, Adobe AIR 4.0) with dotnet webservice integration, but the navigation is not User-Friendly in device. It is getting much delay for the navigation.Is there any solution