Rsync from Runtime.exec

I'm trying to run following command with Runtime.exec:
rsync -auz sourceHost:'path1 path2' tmpSo I have following code to run this command:
command[0] = "rsync";
command[1] = "-auz";
command[2] = "sourceHost:'path1 path2'";
command[3] = "tmp";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
InputStream stdin = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( (line = br.readLine()) != null) {
      System.out.println(line);
stdin = proc.getInputStream();
isr = new InputStreamReader(stdin);
br = new BufferedReader(isr);
line = null;
while ( (line = br.readLine()) != null) {
      System.out.println(line);
int exitVal;
try {
      exitVal = proc.waitFor();
} catch (InterruptedException e) {
      throw new IOException(e.getMessage());
if (exitVal != 0) {
      throw new IOException("Exit value was " + exitVal + " that means an error occured" +
          " during rsync call");
}What happens is that when I run the code rsync gives me following error:
rsync: link_stat "path1 path2" failed: No such file or directory (2)
rsync error: some files could not be transferred (code 23) at main.c(812)
client: nothing to do: perhaps you need to specify some filenames or the --recursive option?
java.io.IOException: Exit value was 23 that means an error occured during rsync call
        at RSyncTest.rsyncBinaryData(RSyncTest.java:156)
        at RSyncTest.main(RSyncTest.java:80)Can anyone think of what's wrong here?
Regards and Thanks,
David

In Java version 1.3 (and later) method exec() of class Runtime returns a Process instance when invoked. The process object returned is what you need to manage.

Similar Messages

  • Running ftp from runtime exec()

    How would I run ftp from exec()? Can I run a script that is ftping from exec()? Why would anyone go through the trouble of writing their own ftp code, if you can just call a script from the exec() method? I am going to be running ftp from a servlet to send a file to a mainframe, where it will run and create an xml file that the servlet will then post to the screen. should I be using java's ftp commands, or will my script way work fine?
    Thanks

    How would I run ftp from exec()?Like any other program. It would be good to read the article http://www.javaworld.com/jw-12-2000/jw-1229-traps.html first to get it right the first time.
    Can I run a script that is ftping from exec()?I don't see any objections.
    Why would anyone go
    through the trouble of writing their own ftp code, if
    you can just call a script from the exec() method?Good question. 1) you are making your application platform dependent by using a platform depenent program 2) Runtime.exec() can't be used in applets but ftp over a socket connection is possible 3) There are already good packages for it (eg. at www.fooware.com) written for it so you don't need to write anything yourself (and 4: just because it's fun!)
    I am going to be running ftp from a servlet to send a
    file to a mainframe, where it will run and create an
    xml file that the servlet will then post to the
    screen. should I be using java's ftp commands, or
    will my script way work fine?
    If you have a working script and you know you will work on only one platform calling a script with exec will be just fine.

  • Displaying input from Runtime.exec()

    Hi there, after all my troubles, I'm finaly able to get all the input from the unix machine using Runtime.exec() and to have it come out pretty quick. My new problem now is that I need to take that input and display it onto a textPane. Anyone who can help me do that? here is the code I have written, along with the method I use called setPaneText():
    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 (Exception ioe)
    ioe.printStackTrace();
    private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    Object source = evt.getSource();
    String serverComm;
    serverComm = "";
    serverComm = pp.getServerComm();
    if(source == jMenuItem13)
    try
    String osName = System.getProperty("os.name");
    Runtime rt = Runtime.getRuntime();
    Process commandReturn = rt.exec(serverComm + " /usr/local/bin/dlgexec pd_rm_cm trashcan");
    //StreamGobbler errorGobbler = new
    //StreamGobbler(commandReturn.getErrorStream(), "ERROR");
    StreamGobbler outputGobbler = new
    StreamGobbler(commandReturn.getInputStream(), "OUTPUT");
    //errorGobbler.start();
    outputGobbler.start();
    int exitVal = commandReturn.waitFor();
    System.out.println("exitVal = " + exitVal);
    if(exitVal == 0)
    System.out.println("inside the trashcan if");
    int cnt = 0;
    String outText []= new String [10000];
    BufferedReader buffy = new BufferedReader(new InputStreamReader(outputGobbler.is));
    while((outText[cnt]=buffy.readLine()) != null)
    cnt++;
    if(cnt == 9000)
    break;
    TextAreaPanel tp;
    tp = new TextAreaPanel();
    for(int cnt2 = 0; cnt2 < cnt; cnt2++)
    String temp;
    temp = outText[cnt2] + "\n";
    tp.setPaneText(temp);
    jPanel1.removeAll();
    jPanel1.add(tp, BorderLayout.CENTER);
    jPanel1.validate();
    this.repaint();
    catch(Throwable t)
    t.printStackTrace();
    and here is the method that I call
    public void setPaneText(String message)
    jTextArea1.setEnabled(true);
    //jTextArea1.setEditable(false);
    String outText = message;
    jTextArea1.setText(message);
    jScrollPane1.setViewportView(jTextArea1);
    //return outText;
    String message;

    @Op. Please learn how to use code formatting when you post code:
    http://forum.java.sun.com/help.jspa?sec=formatting

  • Supressing windows spawned from Runtime.exec()

    Hi,
    I was wondering if anyone had any suggestions on how to suppress windows spawned from using Runtime.exec(program). I've had a good look at the Process object returned from this and cant find a way to do it. I'd like to keep the process being run completely invisible from the user but i'm getting a blank window appear - spawned from the app being run.
    Any ideas?
    TIA,
    Danny

    The exec is called k.exe - its a programming language. I'm writing an interface for a database system called KDB which is implemented in K. (called using 'k db args...').
    Have a look at www.kudib.com if you want to see a bit more about my project or www.kx.com to learn more about K and KDB.
    Danny

  • 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

  • Reading InputStream from Runtime.exec() and ffmpeg?

    I've got a lot of things going on here and I'm having trouble debugging. I'm working on a streaming music player, and the platform only handles MP3 natively. Specifically, the method that handles incoming requests has to return an InputStream for further processing upstream (out of my visibility).
    I'm trying to extend the music player to play AAC files with the extension ".m4a". To do this, my plan is to transcode from MP3 to AAC using Runtime.exec() and ffmpeg, and then return an InputStream that contains the MP3. This works fine if I use ffmpeg to transcode to a temp file, and then return a FileInputStream constructed from that temp file. But like I said, this is supposed to be a steaming music player, and the blocking for the ~30 seconds it takes to completely transcode to a file is too much of a delay.
    So what I'm trying to do is have ffmpeg transcode to stdout, and then use Process.getInputStream() to return the InputStream that contains ffmpeg's stdout while the transcoding is still going on. This doesn't work and I'm not sure why. (I'm fairly new to java, and this is the first time I've used Runtime.) My player just hangs there. I know Runtime is picky about exhausting the stdout and stderr streams, so I'm not sure if it's something related to that, or if I somehow need to buffer the stdout before returning it, or if I need to run something in a different thread, or if I'm just completely barking up the wrong tree.
    If anyone has any experience with something like this, or can point me at some code that implements something similar, I'd appreciate the help.
    Below a sample of the code in question. Also, for what it's worth, all of the console messages that I put in there are printing, but the music doesn't play.
       public InputStream getStream(String uri) throws IOException
                 System.out.println("Entering Factory.getStream()");
                  System.out.flush();
                File file = new File(URLDecoder.decode(uri, "UTF-8"));
                if (file.exists())
                     if(file.getPath().toLowerCase().endsWith(".mp3")) {
                            // This code for playing MP3 files works correctly
                          System.out.println("Playing MP3");
                          System.out.flush();
                          InputStream in = new FileInputStream(file);
                          return in;
                     else if(file.getPath().toLowerCase().endsWith(".m4a")){
                          System.out.println("Playing M4A");
                          System.out.flush();
                          // Create array for ffmpeg command line
                            // This command line transcodes to STDOUT
                          String[] command = { this.ffmpeg_path,
                                                             "-i", 
                                                             "input.m4a",
                                                             "-acodec",
                                                             "libmp3lame",
                                                             "-ac",
                                                             "2",
                                                             "-ab",
                                                             "256",
                                                             "-f",
                                                             "mp3",
                          // Begin transcoding with ffmpeg
                          System.out.println("Transcoding...");
                          System.out.flush();
                          Runtime runtime = Runtime.getRuntime();
                          Process ffmpeg = runtime.exec(command);
                          // Must exhaust error stream, or the application can become deadlocked.
                          System.out.println("Exhausting stderr...");
                          System.out.flush();
                          this.exhaustInputStream(ffmpeg.getErrorStream());
                          // Return ffmpeg's stdout as an input stream
                          System.out.println("Returning stdout...");
                          System.out.flush();
                          return ffmpeg.getInputStream();
                     else {
                          System.out.println("Unsupported Audio File");
                          System.out.flush();
                          return null;
                else
                    // We aren't requesting a file, so let the API handle the request upstream...
                    return super.getStream(uri);
         private void exhaustInputStream(final InputStream inputStream) {
                  // Since InputStream.read() blocks, exhast the stream in a separate thread
                  new Thread() {
                       public void run() {
                            try {
                                 while(inputStream.read() >= 0) {
                                      // Just throw the bytes away
                            catch(IOException e) {
                                 e.printStackTrace();
                  }.start();
             }

    Read this article
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Execute java class from a batch file called from runtime.exec

    Hi.
    I don´t know if this question fits here.
    I wan´t to execute a batch file (on Win XP) with runtime.exec. That batch file will execute another java program.
    I have the following code:
    Resolutor.java
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    public class Resolutor {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Runtime r = Runtime.getRuntime();
              //String[] command = { "cmd.exe", "/C",".\\lanzar.bat .\\ .\\ 001.res:001.dtt" };
              String[] command = { "cmd.exe", "/C",".\\tarea\\lanzar.bat " + args[0] + " " + args[1] + " " + args[2]};
              try {
                   //Process proceso = Runtime.getRuntime().exec("lanzar.bat");
                   Process proceso = Runtime.getRuntime().exec(command);
                   InputStream stderr = proceso.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 = proceso.waitFor();
                   System.out.println("EXITVAL: " + exitVal);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    }lanzar.bat
    java Lanzador %1 %2 %3Lanzador.java
    import java.util.Vector;
    public class Lanzador {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Repetitiva rpt=new Repetitiva();
              String rutaFicheros=args[0];
              String rutaResultado=args[1];
              String[] ficheros=args[2].split(":");
              Vector<String> ficheroDatos=new Vector<String>();
              for(int i=0;i<ficheros.length;i++){
                   ficheroDatos.add(ficheros);
                   System.out.println(ficheros[i]);
              System.out.println("RUTA DE FICHEROS: " + rutaFicheros);
              System.out.println("RUTA DE RESULTADOS: " + rutaResultado);
              System.out.println("CALCULAR");
              rpt.setRepetitiva(ficheroDatos, rutaFicheros, rutaResultado);
              rpt.calcular();
    }I´ve got Resolutor.class in /res and the other two files (and the rest of the files for running) in /res/tarea.
    If I execute /res/tarea/lanzar.bat from the command line everything works fine, it calls java and runs lanzador without problem.
    The problem comes when I try to execute the batch file via Resolutor.class. It executes the batch file without problem, but it throws a *java.lang.NoClassDefFoundError: Lanzador* when launching the new java application.
    Any ideas of how can I solve that problem. (It must do it via batch file).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Well, I tried putting in the bat file java -classpath .\tarea Lanzador %1 %2 %3 and didn´t work.
    I ve tried the bat modification, and the directory in x.txt is k:\res instead of k:\res\tarea.
    I´ve tried to modifiy it to java .\tarea\Lanzador and didn´t work so I have put a cd like the following and it appears to work.
    cd tarea
    java Lanzador %1 %2 %3Thanks for the replies.

  • Capturing output from Runtime.exec()

    I want to be able to get the jvm version by calling "java.exe -version" from within a java application. The following code executes fine (given all the stuff I left out of this post) except for the fact that the inputstream only reads null from the process.
    Anybody have any ideas of why I can't capture the output? This same code works fine if I execute a bat file which calls "java -version".
    final private String[] versionInfo ={"cmd","/c","\"C:\\Program Files\\java\\bin\\java\"", "-version"};
    try{
                   //execute new process
                   System.out.println("executing process");
                   Runtime runtime = Runtime.getRuntime();
                   Process proc = runtime.exec(cmd,env);
                   System.out.println("initializing streams");
                   //read output
                   InputStream inputstream = proc.getInputStream();
                   InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
                   BufferedReader bufferedreader =     new BufferedReader(inputstreamreader);
                   String line;
                   System.out.println("reading output");
                   while ((line = bufferedreader.readLine())!= null){
                        System.out.println("read something");
                        System.out.println(line);
                        outputText.append(line);
                        outputText.append("\r\n");
                        outputText.update();
                   System.out.println("finished reading");
                   //check for errors
                   try {
                        if (proc.waitFor() != 0) {
                             System.err.println("exit value = " + proc.exitValue());
                   }catch (InterruptedException e) {
                        System.err.println(e);
              }catch(Exception e){
                   e.printStackTrace();
              System.out.println("exiting execute method");

    What's wrong with just using one or more of the following System Properties?
    java.vendor=Sun Microsystems Inc.
    java.vendor.url=http://java.sun.com/
    java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
    java.version=1.4.2_04
    java.vm.info=mixed mode
    java.vm.name=Java HotSpot(TM) Client VM
    java.vm.specification.name=Java Virtual Machine Specification
    java.vm.specification.vendor=Sun Microsystems Inc.
    java.vm.specification.version=1.0
    java.vm.vendor=Sun Microsystems Inc.
    java.vm.version=1.4.2_04-b05If you insist on using an external process, this article may help.
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to capture output from Runtime.exec() ?

    Hi,
    Well, the question is in the subject ...
    I'd like to capture the output of a process ran by Runtime.exec() in order to process it.
    thanks,
    ionel

    Okay ...
    Sorry for the post !
    I found the solution : Runtime.exec().getOutputStream()
    Thanks however
    ionel

  • Running C++ application from Runtime.exec

    Hello everybody
    I am trying to run a c++ executable file(myap.exe) using Runtime.getruntime().exec("myap"), nothing happend!.
    Can anyone help me please.

    Where is located the file 'myapp.exe' ?
    If not in directory that is in 'PATH' varable, you need to use :
    Runtime.exec(String command, String[] envp, File dir)
    Executes the specified string command in a separate process with the specified environment and working directory.
    Floweb

  • Return from Runtime.exec()

    Hello all,
    I am executing a Windows 2000 command using Runtime.exec() which establishes a connection using "rasdial" to a remote server. However the exec method returns immediately, before the "rasdial" command has had a chance to complete. Does anyone know of a method which executes an OS command but waits for the command to finish before returning? Something like System would be ideal.
    Any help is appreciated,
    Regards,
    Jason

    In Java version 1.3 (and later) method exec() of class Runtime returns a Process instance when invoked. The process object returned is what you need to manage.

  • Feedback from runtime.exec(command)

    Hi,
    I hope someone can point out the problem with the following. I have a method that is supposed to execute a shell command. The shell command would look something like the following:
    serctl add 351 password [email protected]
    However when this command is executed in a shell/command line a prompt is shown ("MySql password:")asking for a password. Once the user enters the password, the user is added. My code currently executes the first half of the command but gets stuck on the password prompt. My code stops by the line "before the loop" and never enters the inner loop. So obviously my code isn't working properly to say that if the response is a password prompt, to pass it the password variable.
    Any ideas?
    Many Thanks.
    void addUser(String username, String password, String email, String passwd, HttpServletResponse response) throws IOException {
       String[] command = {"serctl", "add", username, password, email};
       //String[] command = {"pstree"};
       Runtime runtime = Runtime.getRuntime();
       Process process = null;
       response.setContentType(CONTENT_TYPE);
       PrintWriter out = response.getWriter();
       String s = "something";
       try {
         process = runtime.exec(command);
         System.out.println("Process is: " + process);
         System.out.println("Command is: " + command);
         BufferedReader in =
         new BufferedReader(new InputStreamReader(process.getInputStream()));
         BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
         OutputStream stdout = process.getOutputStream();
         System.out.println("before the loop");
         s=in.readLine();
         System.out.println(s);
         System.out.println(s);
         System.out.println(in);
         System.out.println(stdout);
         //while((s=in.readLine())!= null)
         while((s=in.readLine()).equals("MySql password: "))
           //s = in.readLine();
           System.out.println(in.readLine());
           System.out.println(s);
           out.println(s);
           if (s.equals("MySql password:  ")) {
             System.out.println("Must be equal to MySql password;");
             //stdout.write(passwd.getBytes());
             //stdout.write(adminpassword);
             //stdout.flush();
             //break;
        System.out.println("after the loop");
         System.out.println("Here is the standard error of the command(if any):\n");
         while ((s = error.readLine()) != null){
           System.out.println(s);
         stdout.close();
         in.close();
         error.close();
         out.println(in);
         out.println("<html>");
         out.println("<body bgcolor=\"#FFFCCC\">");
         out.println("You have successfully added a new user.<br><br>");
         out.println("User " + username + " has been created ");
         out.println("</body></html>");
        catch (Exception e) {
              System.out.println("Uh oh! Error adding new user.");
              e.printStackTrace();
    }

    Just a random observation:
    Sometimes programs that prompt for passwords do it in a way that is impossible to redirect (or at least requires special trickery, such as creating a pseudo-TTY). E.g. in Unix this involves opening /dev/tty and using that instead of stdout & stdin. This is done to make sure there really is a person who knows the password sitting there in front of the teletype.
    I don't know if the "serctl" program does that. If stdout&stdin redirection does not appear to work then it is a possibility.
    A quick googling for "serctl" reveals:
    Commands labeled with (*) will prompt for a MySQL password.
    If the variable PW is set, the password will not be prompted.
    which might or might not be an easier way to deal with this particular program. If it indeed is the same "serctl" program.

  • Problem opening a file from Runtime.exec()

    hi
    I'm trying to open a certificate (.cer), from my java code.
    If I go on a windows command, and I type only the name of my certificate ( f:\certificate.cer), it is opened.
    If I use the java code
    Process process = Runtime.getRuntime().exec("F:\\certificate.cer");it doesn't work:
    java.io.IOException: CreateProcess: "f:\oid.crt" error=193
    anybody knows what I can do to make it work?
    Thanks in advance
    Philippe

    For windows you need to used the cmd.exe to do what you want.
    i.e. cmd /c f:\certificate.cer
    Process process = Runtime.getRuntime().exec("cmd.exe /c F:\\certificate.cer");At a command prompt, for more help on cmd.exe type: cmd /?
    Also for help on a related command, type: start /?
    Also read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Accesing environment variables from Runtime.exec()

    Hi All,
    I have a problem for which I need help. I have a property BLAH set to "abc" in my ~/.bashrc. My programme looks as following.
    Runtime rt = Runtime.getRuntime();
    String command="java -Dext.prop=${BLAH} Test1";
    //Even following also dont work I removed curly braces
    // String command="java -Dext.prop=$BLAH Test1";
    try {
    rt.exec(command);
    } catch (IOException e) {
    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    I just want to set the value of environment variable to a property "ext.prop" and in class Test1 I would like to access it as System.getProperty("ext.prop"). The problem is that the value of System.getProperty("ext.prop") is $BLAH instead of "abc" which I set in my ~/.bashrc.
    If I execute the same command ("java -Dext.prop=${BLAH} Test1") from command prompt then I don't have any problem. I tried in another way also that is
    Edited by: ragsger on Dec 22, 2008 12:59 PM
    Edited by: ragsger on Dec 22, 2008 1:00 PM

    Replacing $BLAH with the value of the environment variable BLAH is handled by the shell and since you don't call a shell, you'll have to do that on your own.
    System.getenv("BLAH") will get the value.

  • Problem  in  executing dos command from runtime.exec(String command);

    Hi
    i have wriiten a code for running command of DOS-Promt
    try
         rnt1 = Runtime.getRuntime();
                                  proc1= rnt1.exec("myb");//myb is a batch file      and proc1 is process class instance
                                                                try
                                  proc1.waitFor();
                                  catch (InterruptedException e)
                             System.out.println("InterruptedException raised: "+e.getMessage());
                   catch (IOException ioe)
              System.out.println("IOException raised: "+ioe.getMessage());
    But it is giving error while running:
    this is showing as an IO exception
    CreateProcess: myb error=0
    Please help me how to proceed
    Thanks

    There are 2 possible reasons (perhaps concurrent):
    1. The file to be executed is not in the same path of your application, and you MUST specify its whole absolute path as exec() argument;
    2. The file to be execute is really (as you call it) a DOS batch file, and then it HAS TO BE NAMED (and called) myb.BAT or (under NT/2000) myb.CMD; WinDOS is Not Unix (WNU): extensions rule!!!

Maybe you are looking for