GetRuntime().exec problems

Hello,
I recently started working on a program and I wanted to use some batch coding along with java for several reasons. However, I coulden't get it to work, bellow are the many things I've tryed:
          try{ Process p = Runtime.getRuntime().exec("cmd /c c:/TIME.bat") ; }
          catch(Exception e){ System.out.println(e); }Variations on such include:
�     Runtime.getRuntime().exec("cmd /c c:/TIME.bat")
�     Runtime.getRuntime().exec("cmd c:/TIME.bat")
�     Runtime.getRuntime().exec("cmd c:\\TIME.bat")
// I also tried moving the file into the project folder and then executed it:
�     Runtime.getRuntime().exec("cmd TIME.bat")From reading responses to people with a similar problem I tried also to change the .bat extension to ".cmd" but this to wasn't successful either.
The file seems to run, since the dos black screen appears, but it doesen't concude the operation. I read the "Runtime.exec pitfals", but it seems as though the problem there mentioned is not the same as I face.
I am using eclipse, but the same problem seems to appear in netbeans. Java returns no errors.
The batch file I am trying to execute is this:
@ECHO off
ECHO %TIME% > TIME.dat
:end If executed from dos or by double click it will work, writing out the current time in the file TIME.dat .
Though I know that you can do the same as this command does, I am using this meerly as a test.
Help would be appreciated,
     --andrelloyd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

baftos wrote:
public static void main( String[] args ) throws Exception
Runtime.getRuntime().exec("cmd /C c:\\time.bat");
System.out.println( new File(".").getCanonicalPath() );
}This works fine on my machine. The last line is there, so that you know where to find your TIME.DAT file.Thank you very much, this worked for me perfectly.
     --andrelloyd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Runtime.getRuntime().exec problems

    i am trying to run files from my java application, i use the following command
    Runtime.getRuntime().exec("cmd /c start " + filePath);but it seems that it cant handle file path with spaces, like
    C:\Documents and Settings\Administrator\My Documents\My Web\Untitled-3.fla
    it works well with path like this
    C:\Downloads\1.rar
    am i right? and how to solve this problem? thanks

            final String[] command =
                "cmd.exe",
                "/C",
                "start \"" + filename + "\"",
            final Process p = Runtime.getRuntime().exec(command);this method can only trigger files in the same folder as the java application, isnt it?

  • Runtime.getRuntime().exec() problem while getting Mozilla version.

    Hi all,
    I've trying to get the current mozilla version in Java side using
    Runtime.getRuntime().exec(). The sample code is as below.
    I've tested two cases using exec(), as case# 1 and case# 2.
    The result is after the code.
    try
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(new String[] {"mozilla", "-remote"}); //case# 1
    //Process proc = rt.exec(new String[] {"mozilla", "-version"}); //case# 2
    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();
    // execute "mozilla -remote"(case# 1)
    $ java TestExec
    <ERROR>
    -remote requires an argument
    </ERROR>
    Process exitValue: 1
    // execute "mozilla -version"(case# 2)
    $ java TestExec
    <ERROR>
    </ERROR>
    Process exitValue: 0
    I'm just surprised that why case# 2 couldn't get the returned version string as case #1 ? Since there will be version string be returned from command line:
    $ mozilla -version
    Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830, build 2002083014
    Could anybody explain the problem or give any solution ?
    Thanks.
    -George.

    Hi all,
    One more question here.
    While I use Runtime.getRuntime().exec() to execute some commands,
    the commands may fail for some reason. Generally, they will return with the exit
    value set to 1 or others. But sometime, before waitFor() exits, there is a popped up
    dialog giving some info, and only after I click the "OK" button, it dispears, and
    waitFor() returns the exit value.
    So I'm not sure that could I suppress this popped up dialog, and make it run
    just like other commands ? I mean, just get the exit value by waitFor() without user
    interferance ?
    Thanks.
    -George.

  • Runtime.getRuntime().exec problems running with applet

    Hi,
    I am running the command
    Process prc = Runtime.getRuntime().exec("net config workstation");
    InputStream in = prc.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    line = br.readLine();
    When running from an application(/stand alone program) on Win-NT it runs fine. But when i include the same code in an Applet and try to run.
    It doesnt return any thing. I see the DOS-prompt open and close and i can also see the required output generated on the DOS prompt, but the program doesnt return any results(null) in the InputStream.
    I even tried to get the ErrorStream incase it is writing some error but it doesnt write anything.
    I tried running some other commands like (cmd.exe /c set) which were able to run on both application as well as from the applet.
    I have tried giving the "net config workstation" command in all flavors
         String[] cmd = new String[3];
         cmd[0] = "cmd.exe";
         cmd[1] = "/C";
         cmd[2] = "net config workstation";     
    And      
         String[] cmd = new String[3];
         cmd[0] = "net.exe";
         cmd[1] = "config";
         cmd[2] = "workstation";          
    AND
         String[] cmd = new String[5];
         cmd[0] = "cmd.exe";
         cmd[1] = "/C";
         cmd[2] = "net.exe";
         cmd[3] = "config";
         cmd[4] = "workstation";     
    AND giing the full path as
    C:\winnt\system32\net.exe config workstation
    But still it doesnt work.
    Can anybody please suggest what is the problem.Its Urgent.....
    Well the purpose of this is to get users system properties like the Logon Domain , server name etc.... or else can anybody suggest a better way to obtain this information.....
    Your reply will be highly appriciated...
    Thanks in Advance......

    Thanks for atleast replying.....
    Sorry, i forgot to mention.... yes OfCourse, i am using an Signed Applet..... That how i was able to run the "set" command.....
    I have made sure it is not sucha simple problem..... the thing is as i have mentioned i know that even "net config workstation" works..... cause i see the output on the DOS prompt,.... but this output is not returned to the Applet in the getInputStream()/getErrorStream().....
    Can anybody please suggest a way to get this output..... OR is there some other way to get the machine's domain, server name etc info from the machine....?????
    Thanks in Advance...!!

  • GetRuntime().exec problem

    I am trying to set a password for a user on a linux box but getRuntime().exec won't cooperate. I have researched this topic to death and haven't been able to find any solutions. I've rewritten the exec() and code several different ways and get no reponse or error message except when trying to use a pipe in the command, which is basically useless because I can't find any listing of what the error codes mean.
    In code previous to this the user is successfully added. This code tries to set the password. Under linux the system should prompt for the new password twice once the passwd command is executed. I read the input and error streams and get nothing. Depending on the way its coded the system either appears to hang (waiting on input?) or the waitFor() returns an error.
    Thanks for helping,
    Bob
    <PRE>
    try {
    proc = Runtime.getRuntime().exec("passwd " + this.usersName );
    InputStream istr = proc.getInputStream();
    InputStream estr = proc.getErrorStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(istr));
    BufferedReader er = new BufferedReader(new InputStreamReader(estr));
    OutputStream output = proc.getOutputStream();
    PrintWriter outputWriter = new PrintWriter ( new OutputStreamWriter(output));
    // Get streams, write password
    String str;
    while ((str = er.readLine()) != null)
    logger.debug(str);
    while ((str = br.readLine()) != null)
    logger.debug(str);
    outputWriter.println(newpasswd);
    // Get streams, write password again
    while ((str = er.readLine()) != null)
    logger.debug(str);
    while ((str = br.readLine()) != null)
    logger.debug(str);
    outputWriter.println(newpasswd);
    if (proc.waitFor() != 0) {
    logger.error("Error setting password)");
    error = true;
    return false;}
    } catch(InterruptedException ex) {
    logger.error("Exception interrupted");
    } catch(IOException e) {
    logger.error("IOException error setting password.");
    error = true;
    return false; }
    </PRE>

    I saw running of different threads at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html but thought it was a bit of overkill for a simple procedure.
    I was about to give up on this because the waitFor() would never exit.I used output.flush(), but apparently the process doesn't close until the output stream is closed. Another strange thing is half the input comes over the error stream and half over the output stream.Not for me to worry about because my problem is solved. The Thread.wait() seems to be important otherwise I get a conversation error.
    I only point this out so that later when someone else is looking it may be a bit easier than it was for me. People tend not to post a solution when they finally find the answer they are looking for. I searched, and though there were a lot of questions relating to this exact problem, nobody posted anything they found out.
    One of my clients blessed me this morning, so it must have been divine inspiration that lead me to the right combination that finally worked. The first waitfor() and flush() appear to be necessary. The second waitfor() is necessary but I didn't check the flush(). I doubt it is necessary, but what the heck, it works.
    Here is my final code that does work.
      Process proc = null;
      try {
        proc = Runtime.getRuntime().exec("/usr/bin/passwd " + this.usersName );
        OutputStream output = proc.getOutputStream();
        PrintWriter outputWriter = new PrintWriter(new OutputStreamWriter(output));
        // Get the messages
        StreamGobbler eg = new StreamGobbler(proc.getErrorStream(), "ERROR");           
        StreamGobbler og = new StreamGobbler(proc.getInputStream(), "OUTPUT");
        eg.start();
        og.start();
        Thread.sleep(500);
        outputWriter.println(newpasswd);
        outputWriter.flush();
        Thread.sleep(500);
        outputWriter.println(newpasswd);
        outputWriter.flush();
        outputWriter.close();
        if (proc.waitFor() != 0) {
          logger.error("Error setting password)");
          error = true; }
        } catch(InterruptedException ex) {
          logger.error("Exception interrupted");
        } catch(IOException e) {
          logger.error("IOException error setting password.");
          error = true; }
    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)
                   logger.debug(type + ">" + line);   
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
        }

  • GetRuntime().exec problem under Linux

    Here's a piece of code under Mandrake.
                Process p;
                try
                    p=Runtime.getRuntime().exec("/usr/local/WordNet-3.0/bin/./wn " + englishword + " -hypen > /home/istvan/wordnet/Kimenetek/ki.txt"); //"englishword" is a String
                    //p=Runtime.getRuntime().exec("ls");
                    try {p.waitFor();}
                       catch (InterruptedException ex1) {System.out.println(ex1.getMessage());}
                    System.out.println(p.getInputStream().toString()); // ---> "java.io.BufferedInputStream@1bcc0bc"
                    System.out.println(p.getErrorStream().toString()); // ---> "java.io.FileInputStream@111a3a4"
                   catch (IOException ex) {System.out.println(ex.getMessage());} It does absolutely nothing, doesn't create the desired "ki.txt" file, although from the command line works just fine. In fact, even at the simple "ls" command gives the message mentioned in the code as a comment.
    Can somebody help me? Thanks in advance.

    There are several problems.
    First of all, the "command > somefile" syntax is interpreted by
    the shell on Linux. But exec does not load the shell by default.
    So the redirection does not work.
    Secondly, you should not execute the program as is,
    and then read its output using "getInputStream()" afterwards.
    There is buffer overflow and data starvation issues.
    See this excellent tutorial for how to create separate
    threads to channel data to and from a subprocess:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Runtime.getRuntime.exec() Problem

    hi,
    I want convert MS Office documents to PDF through my aaplication which is online. I'm using PDFCreator.exe for doing this.
    From a standalone Java program the command is executed properly.
    But If I call the same program from a JSP the PDFCreator.exe is started, but it doesnt convert the document to PDF, also the .exe keeps on running for a long time and does not exit. the JSP prints "Files Converted" before the Java program has finished execution or give error as "Proocess has not exited".
    My JSP code:
    <%@ page import="java.io.*,java.util.*"%>
    <%@ page import="pack.Test.*"%>
    <%
    try{
    pack.Test t=new pack.Test(); //initialixe the java class
    t.print();//call  the function
    }catch(Exception e) {e.printStackTrace();}
    %>
    <br>File Converted Code for Java program:
    package pack;
    import java.io.*;
    import java.lang.Process;
    import java.lang.Runtime;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class  Test
    Process p;
    Runtime r;
    BufferedReader stdInput,stdError,br,buff,Input;
    int i=0;
    public void print()
    String cmd="C:\\Program Files\\PDFCreator\\PDFCreator.exe /NOSTART /PF
    \"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\
    \Reports\\1.doc\"";
    System.out.println("In print="+cmd);
    try{
    p = r.getRuntime().exec(cmd);
    //p.waitFor();
    stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    System.out.println("Input="+stdInput);
    System.out.println("Error="+stdError);
    } catch(IOException ioe){System.out.println("Exception="+ioe);}
    //catch(InterruptedException ie){System.out.println("Exception="+ie);}
    } //end of print fnction
    } //end of class Even if I dont use waitFor() then too the process continues for a long
    time without any output.

    Read the following.
    [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1]

  • Runtime.getRuntime().exec problem with linux script.

    Hello,
    I try to start a script under Linux RedHat 9. This script must just create another file.
    I work with JDK 1.4.1_02b06.
    If I use the next command
    process = Runtime.getRuntime().exec("/temp/myScript.sh");
    This is not working. I script file is existing otherwise I receive an error. I don't understand why the script is not executed!
    I have check some other posts in this forum but I cannot find the solution.
    Thanks in advance for your help.
    Alain.

    Try running it with sh: Runtime.getRuntime().exec("sh /temp/myScript.sh");

  • Runtime.getRuntime().exec(...) problems and exit codes

    Hi,
    I am trying to launch an application 4 times with different arguments from a Java app. I have tried doing it sequentially and in four different threads, but the results are the same: sometimes the 4 of them are properly launched, sometimes (the most of the times) only 3 are launched and sometimes only 2. I have tried with cmd and cmdarray[] as parameters for exec but the results are the same.
    This is one of the four threads I use:
    Runnable r1 = new Runnable(){
                        public void run(){
                             String ecgCommand = "./flute -S -m:" + Config.ECGS_FLUTE_IP + " -p:" + Config.ECGS_FLUTE_PORT + " -F:" + Config.ECGS + " -r:" + Config.ECGS_FLUTE_RATE + " -C";
                             System.out.println(ecgCommand);
                             InputStream ecgsStream = null;
                             InputStreamReader isr = null;
                             BufferedReader br = null;
                             try{
                                  ecgsProcess = Runtime.getRuntime().exec(ecgCommand, null, new File(Config.HOME_PATH + Config.FLUTE_PATH));
                                  String line;
                                  ecgsStream = ecgsProcess.getInputStream();
                                  isr = new InputStreamReader(ecgsStream);
                                  br = new BufferedReader(isr);
                                  StyledDocument styleDoc = mm.ecgFluteMessages.getStyledDocument();
                                  Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
                                  while((line = br.readLine()) != null && running){
                                       if(styleDoc.getLength() > 25000)     mm.ecgFluteMessages.setText("");
                                       styleDoc.insertString(styleDoc.getLength(), line+ "\n", def);
                                       mm.ecgFluteMessages.setCaretPosition(mm.ecgFluteMessages.getDocument().getLength());
                                  System.out.println(ecgsProcess.waitFor());
                             }catch(Exception e){
                                  try {
                                       br.close();
                                       isr.close();
                                       ecgsStream.close();
                                  } catch (Exception e1) {
                                       e.printStackTrace();
                   new Thread(r1).start();Adding a Thread.sleep between runnables doesn't have any effect.
    In addition, those processes that are not properly launched return an exit value of 255. I have searched for its meaning but I have found nothing. Could anybody tell me where can I find a list of the JVM exit codes in order to guess what is happening?
    Can anybody help me with this issue? Help is much appreciated.
    Thanks a lot

    I have been looking for it but it seems it has not any exit code list or any documentation regarding this. Anyway, I think 255 is a JVM error code (the last one, errors are numbered in modulo 256) which means that the error has nothing to do with JVM but with the application execution (flute in my case).
    I have added a prompt for the errorStream and I have this message for the 255 exited programs:
    not well-formed (invalid token) at line 15+
    And the four commands are like this:
    *./flute -S -m:239.255.255.253 -p:60102 -F:./ecgs -r:150 -C*
    *./flute -S -m:239.255.255.252 -p:60103 -F:./ads -r:150 -C*
    *./flute -S -m:239.255.255.251 -p:60104 -F:./pushvod -r:50 -C*
    *./flute -S -m:239.255.255.250 -p:60105 -F:./banners -r:150 -C*
    So, as the process is sometimes initialized properly and others it is not, it seems that there is a problem with the tokenizing of the command not happening always. As I have tried it with a single command line and with an array of command strings (the first for "./flute" and the followings for each argument) with the same results I can't understand why is this problem happening sometimes. Happening always would help me in giving a clue but that's not the case.
    Any idea? Thanks a lot.
    Edited by: dulceangustia on Apr 3, 2008 3:41 AM

  • Runtime.getRuntime().exec portability problem

    Hello everyone!
    I've got a problem with running external application (in my case it's pdfLaTeX). The code looks as follows:
    System.out.println(AppConfig.getExeFile() + " " + params); // AppConfig.getExeFile() is a static function that outputs a String object.
    Process p = Runtime.getRuntime().exec(AppConfig.getExeFile() + " " + params); // params is a String object as well.
    p.waitFor();
    // ...On Linux everything works great. System.out.println() outputs the following line:
    /opt/texlive/bin/pdflatex -halt-on-error   -output-directory /tmp   /tmp/tabular.texThe application executes successfully.
    However, I can't get my program to run on Windows. In this case, the generated command looks as follows:
    "C:\Program Files\LaTeX\MiKTeX 2.7\miktex\bin\pdflatex.exe" -halt-on-error   -output-directory C:\DOCUME~1\Roman\USTAWI~1\Temp   C:\DOCUME~1\Roman\USTAWI~1\Temp\tabular.texAfter displaying this line, my application freezes. The child process (pdflatex.exe) is frozen as well. Then I kill both processes.
    Here's the PdfLaTeX's log file after failure:
    {C:/Documents and Settings/All Users/Dane aplikacji/MiKTeX/2.7/pdftex/config/pd
    ftex.map}
    !pdfTeX error:  (file C:/Documents and Settings/All Users/Dane aplikacji/MiKTeX
    /2.7/pdftex/config/pdftex.map): fflush() failed
    ==> Fatal error occurred, no output PDF file produced!and here's how it should look like:
    {C:/Documents and Settings/All Users/Dane aplikacji/MiKTeX/2.7/pdftex/config/pd
    ftex.map}] (tabular.aux) )
    Here is how much of TeX's memory you used:
    202 strings out of 95340
    2116 string characters out of 1183965
    46926 words of memory out of 1500000
    3474 multiletter control sequences out of 110000
    3640 words of font info for 14 fonts, out of 1200000 for 2000
    14 hyphenation exceptions out of 8191
    23i,6n,17p,173b,100s stack positions out of 5000i,500n,10000p,200000b,5000s
    <C:/Program Files/LaTeX/MiKTeX 2.7/fonts/type1/bluesk
    y/cm/cmr10.pfb>
    Output written on tabular.pdf (1 page, 10003 bytes).
    PDF statistics:
    10 PDF objects out of 1000 (max. 8388607)
    0 named destinations out of 1000 (max. 131072)
    1 words of extra memory for PDF output out of 10000 (max. 10000000)I suspected that the problem was caused by presence of spaces in command (I've tried several other solutions such as putting parameters into String[] array, escaping, adding double-quotes, putting the command to the batch file), but when I run my the same command from the command line, everything works fine.
    I believe that I'm making some kind of a stupid mistake because it doesn't look like it's pdfLaTeX's fault.
    Thanks in advance for your hints. Solutions are welcome as well ;-)

    Hi,
    What is probably happening is that the process is being blocked because you are not reading the output.
    This is a common problem with exec.
    Read this article:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    HTH,
    Eugenio Alvarez

  • GetRuntime.exec() and Event Problems

    While it seems like this topic has been beat to death, I'm still perplexed by a situation that I've run into. I have a Swing application A which starts Swing application B by calling getRuntime.exec("start c:\\java applicationB"). This works and application B gets up and running with no problems.
    However, application B does not run smoothly at all. It almost seems like apps A and B are sharing the same event queue/thread etc. B gets frequently stuck for no apparent reason and doesn't seem to be getting any events. Then, sometimes when I move B's frame window around or minimize it, all of the sudden it breaks free and the events occur in rapid succession. Other times it just gets permanently stuck. It's like events are being queued, but not properly switched to application B.
    I know the problem is not application B, as it runs perfectly when I start it on its own. To me it seems like a bug, but maybe I'm not starting app B the right way. Is there some trick I should know to avoid some pitfall?
    I am using Jre 1.3.x on Windows 98. Application B makes use of sockets.
    Here's hoping,
    Mike

    I ran a quick test using the following program:
    public class ExecuteCommand
         public static void main(String args[])
              throws Exception
    //          Process proc = Runtime.getRuntime().exec("c:/windows/notepad.exe");
              Process proc = Runtime.getRuntime().exec("java TextComponentDemo");
    When I test Notepad:
    a) the ExecuteCommand class finishes executing normally
    b) Notepad is still executing when the class finishes.
    When I test TextComponentDemo the ExecuteCommand class does not finish executing until:
    a) I close the TextComponentDemo frame or
    b) I use Ctrl-C to kill the ExecuteCommand class
    So, you may be right. Maybe both apps share the same event thread.
    Try creating a separate thread and start app B from within that thread.

  • GetRuntime exec exception problems

    Greetings,
    I am having problems with exceptions. I have a class file called ShowPDF which consists of:
    -=-=-
    package StairSpecs;
    public class ShowPDF {
    public ShowPDF(String[] args) throws Exception {
    try {
    Process p = Runtime.getRuntime().exec("C:\\StairSpecs\\showpdf.bat C:\\StairSpecs\\" + Generate.FileName.getText());
    p.waitFor();
    System.out.println("Done.");
    } catch (Exception e) {
    System.out.println(e);
    -=-=-=-
    Basically, the class executes a (MS Win) bat file which in turn opens a PDF file (whose name comes from another class -- Generate --)
    In my Generate class I am calling the ShowPDF class with:
    -=-=-=
    new ShowPDF(null);
    -=-=-=
    However, I can't build due to the following error:
    unreported exception java.lang.Exception; must be caught or declared to be thrown
    new ShowPDF(null);
    So really, I'm very new to this and have very little idea what I'm doing wrong (or right for that matter). Can someone help me sort out my problem?
    Cheers!

    Annie,
    Again, thanks for your quick reply. After your first reply I removed the "throws Exception" along with the catch block assuming they are connected. After your last post I removed "throws Exception" but kept the catch block. And then it all worked. :-)
    I think I understand how the catch block is for the exceptions thrown by the getRuntime.exec(), and that I was adding an additional exception throw on top of that.
    I have a long way to got to understand how this all works, but these little successes, with your guidance, sure help me want to stick with it.
    Thanks so much!

  • Ran into an interesting problem with getRuntime().exec()

    Hi,
    I'm trying to run a application using getRuntime().exec(). When I run the prgram from the command prompt everything goes ok, but when I start it from my java application, I get and error and the program exits.
    The executable I call withing my application is a bat file that sets the neccessary environmental variables (for now) and executes the right exe files. Exactly the same bat file I can start at the command prompt. I've also tried calling cmd /c to start the program and directly calling the exe started by the bat file.
    Below is the error I get. I have a hunch the program is made with Fortran.
    Can't read communication file
    Filing error number 7: FNF:File not found
    : Unable to open communications file to read
    There should be nothing wrong with my code and I can read and control the program. The problem occures when I try to change the mode withing the program, that makes it try to start a new process.
    What's the difference between starting a program manually through the command prompt and executing it using getRuntime().exec()?
    Br,
    Tom

    I'm just wondering how exec() can be different from using the command line in windows. I even execute my java app in the same directory and it uses the same commands.

  • Problems with getRuntime().exec()

    Hello!
    I'd like to start a process which will run a C executable.
    The C executable named dbc is placed in the folder
    /home/swkm/services/rul_hyb/rul-1.0/bin and accepts as an argument the name of a database, for example, myDB
    I tried the following code:
       File f = new File(filePath);
              Process process = Runtime.getRuntime().exec
                   new String[]
                        "dbc",
                        "myDB"
                   }, null,f
              );where filePath is the above mentioned path.
    The problem is that I receive an:
    java.io.IOException: java.io.IOException: dbc: not found
         at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
    I tried the new Tiger version of ProcessBuilder in the following manner:
    ProcessBuilder process = new ProcessBuilder
                   new String[]
                        "dbc",
                        "myDB"
                  process.directory(new File(path));
                  Process p=process.start();but I got the same exception: "dbc not found"
    Do you have any idea what is going wrong?
    Thank you very much
    With best regards,
    Sorin

    Are you assuming that the executable executes from the directory defined by 'filePath' ? If so then this is wrong - the executable must be in a directory in the PATH environment variable or you must specify the full path to the executable.
    The third argument in the exec() command is the working directory for the process and does not modify the PATH environment variable.
    P.S. It does not matter whether you use Runtime.exec() or ProcessBuilder becauuse behind the scenes Runtime.exec() just wraps ProcessBuilder.
    Message was edited by:
    sabre150

  • Problem with Runtime.getRuntime().exec

    Hi ,
    i'm using jBuilderX and windows 2000 server . My problem is that i can't
    find why
    in my code it doesn't work this:
    import java.lang.*;
    String command = new String("c:\\testd\\testf.bat"); // testf.bat -
    batch file
    Runtime.getRuntime().exec(command); // it doesn't
    have any effect
    Thanks in advance,

    What's it supposed to do?
    I can definitely help you on this 1, but I'd really like to see your streamoutputs. You can get these from the Process object that is created, but you'll need to add some threaded listeners to get the data.
    Is this possible?

Maybe you are looking for

  • Connecting to my 1024x768 lcd tv - promise of success then failure

    Hello Forum, I have been trying off and on for 18 months to connect my G5 to my JVC LT-Z37EX6 through the PC-in port. I have the adapter to make the connection, and at start-up the white screen with the apple shows up on the TV; as soon as it switche

  • Cannot use Forms in Acrobat 9.3 Pro

    It was working fine, then I had someone else working on the forms for a large PDF, they were almost finished, and then said they couldn't add fields anymore. So they closed and saved it, then i started looking on my end and sure enough, we can no lon

  • Errors: Business partner of organizational unit 50024549 has no address

    Hello all, I have this message error if I try to create a user in EBP browser.And that I verify this organisational structure and I have a good shipping and billing adresss. Please help me resolve my problem. Thanks

  • Restriction for  Characteristic in CT04

    Dear Experts, i want to restrict the characteristics which only certain user can access those characteristic. i already follow the http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a0d22ea5-7643-2c10-97a1-fd9e6e5683ef?quicklink=index

  • Cannot make in-app purchases or retrieve purchased in-game content

    HELP!! Before anything else, this problem started immediately after the big iTunes update a few weeks ago. I have 32gb/3rd gen ipod Touch and it should not be experiencing these problems. I have latest software, also have in-app purchases turned on i