Runtime.exec  problems

Hi
I would like to open a chm file from my "help" menu.
I got two problem related to that:
1.The first time the menu is clicked i start the process and the help is opened on top of my application frame.
but - the second time It is opened - the only wat to recognize i sthe process is still active is to call exitValue (if it get an exception - process is still active) but - how can i make the frame on top of my application frame( the current active frame)
2.when the application is closed the help application does not "die" with the rest of the application.
I will be happy to get some ideas of how can i control it.
this is my code:
Runtime runtime=  Runtime.getRuntime();
        try {
            if(process==null){
                 process=runtime.exec(new String[] {"cmd.exe","/c" , helpLink});
            else{
                try {
                    process.exitValue();
                    process = runtime.exec(new String[]{"cmd.exe", "/c", helpLink});
                    if (log.isDebugEnabled())
                        log.debug("process finish working");
                } catch (IllegalThreadStateException e1) {
                    if (log.isDebugEnabled())
                        log.debug("process still working");
        } catch (IOException e1) {
            if (log.isErrorEnabled()){
                log.error("could not open help file"+ helpLink);
                log.error("exception:",e1);
            WorkingAreaManager.getWorkingAreaManagerInstance().displayErrorMessage(COULD_OPEN_HELP);
        }thanks,Liat

1.The first time the menu is clicked i start the
process and the help is opened on top of my
application frame.
but - the second time It is opened - the only wat to
recognize i sthe process is still active is to call
exitValue (if it get an exception - process is still
active) but - how can i make the frame on top of my
application frame( the current active frame)Sorry I don't know the answer to that. What happens if you invoke it a second time... does it bring up a completely new frame?
2.when the application is closed the help application
does not "die" with the rest of the application.
I will be happy to get some ideas of how can i
control it.process.destroy()?

Similar Messages

  • Java.lang.Runtime.exec problem in ubuntu 9.10

    Hi:
    I tried to run some command in the java code , for example "grass64 -text /home/data/location", this command works well in the terminal, however when I call it in the java code I got some excepetions.
    My code is :
    public class Grass {
         public static String grassBatJob="GRASS_BATCH_JOB";
         public void run(String cmd,String jobPath) {
              //set the environments variables
              Map<String, String> env=new HashMap<String, String>();
              env.put(grassBatJob, jobPath);
              String gisDataBase="/home/kk/grass/GrassDataBase";
              String location="spearfish60";
              String mapset="PERMANENT";
              cmd=cmd+" "+gisDataBase+"/"+location+"/"+mapset;
              CommandLine line=new CommandLine(cmd);
              //the real cmd should be >>grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT
              System.out.println("start line=="+line.toString());
              DefaultExecutor de=new DefaultExecutor();
              try {
                   int index=de.execute(line,env);
                   System.out.println(index);
              } catch (ExecuteException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              String jobPath=Grass.class.getResource("grass.sh").getFile();
              new Grass().run("grass64 -text", jobPath);
    The real cmd I want to execute is "grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT" with the envrionment variable "GRASS_BATCH_JOB=jobPath",it works well in the ternimal ,however in my application I got the exception"
    java.io.IOException: Cannot run program "grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT": java.io.IOException: error=2, No such file or directory
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
         at java.lang.Runtime.exec(Runtime.java:593)
         at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
         at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246)
         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:302)
         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
         at org.kingxip.Grass.run(Grass.java:27)
         at org.kingxip.Grass.main(Grass.java:38)
    Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
         at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
         at java.lang.ProcessImpl.start(ProcessImpl.java:65)
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
         ... 7 more
    I wonder why?

    Thanks for all of your reply, and now I can run the command, however I met some problems when I tried to get the result of the exec.
    The core codes are shown below:
    String cmd="g.version";
    String[] exe={"bash","-c",cmd};
    Process p1=Runtime.getRuntime.exec(exe,env); // the env has been set
    GrassThread outThread=new GrassThread("out", p1.getInputStream());
    outThread.start();
    GrassThread errorThread=new GrassThread("error", p1.getErrorStream());
    errorThread.start();
    int exitVal = p1.waitFor();
    String resu=outThread.sb.toString();
    System.out.println("==========the output start========");
    System.out.println(resu);
    System.out.println("==========the output end========");
    System.out.println("ExitValue: " + exitVal); //------------------> line one
    public class GrassThread extends Thread{
         public StringBuffer sb=new StringBuffer();
         public GrassThread(String type,InputStream is) {
              this.type=type;
              this.is=is;
         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);
                        sb.append(line).append("\r");  // ----------------------------> line two
    }I define a StringBuffer in the GrassThread to save the output (see the code where I marked by "line two"), and when the process complete, I check the StringBuffer to get the output (see code where I marked by "line one"), however the output in the console of the IDE are :
    ----------- output in the console of the IDE start -------------
    ==========the output start========
    ==========the output end========
    ExitValue: 0
    out>GRASS 6.4.0RC5 (2009)
    ----------output in the console of the IDE end--------------------
    I can not understand, in the code "line one", I first get the output using "System.out.println(resu);",then I print the exitvalue,but why the order of the output in the console is not what I expected?
    Another question, the code above assume the output can be got from the Process's getInputStream, however sometimes the output maybe come from the Process's getErrorStream, so how to handle it?
    Edited by: apachemaven on 2010-3-5 ??5:38

  • Runtime.exec--problems writing to external file

    Hi. I went to http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html, and am still quite confused regarding the use of Runtime.exec, for my purposes. I want to decompile a CLASS file using javap, and then write that to a TXT file, for easier reading/input to JAVA. Now, I use the following code (a modification of what I got from http://www.mountainstorm.com/publications/javazine.html, as the "traps" article's sample code is WAY too confusing--they say the compiler had the output sent to text.txt, without even showing how in the source code they did that), but it hangs up. Modifications to the string array cause different results, such as showing the javap help menu, or saying that the class wasn't found, but I think the way I did the array here is right:
    import java.util.*;
    import java.io.*;
    public class Test {
            try {
             String ls_str;
                String[] cmd = {"C:\\j2sdk1.4.2_04\\bin\\javap", "-c", "-classpath", "H:\\Java\\metricTest", "metricTest > blah.txt", ""};
                Process ls_proc = Runtime.getRuntime().exec(cmd);
             // get its output (your input) stream
             DataInputStream ls_in = new DataInputStream(
                                              ls_proc.getInputStream());
             try {
              while ((ls_str = ls_in.readLine()) != null) {
                  System.out.println(ls_str);
             } catch (IOException e) {
              System.exit(0);
         } catch (IOException e1) {
             System.err.println(e1);
             System.exit(1);
         System.exit(0);
    }

    Also, jesie, I realize that's what I need...the only
    problem is, the name "test.txt" is nowhere to be found
    in the source code! lolLooks like I have to explain this, then.
    When you look at a Java program you'll notice that it always has a "main" method whose signature looks like this:public static void main(String[] args)When you execute that program from the command line, it takes whatever strings you put after the class name and passes them to the main program as that array of strings. For example if you run it likejava UselessProgram foo bar hippothen the "java" command takes the three strings "foo", "bar", and "hippo" and puts them into that args[] array before calling the "main" method.
    That means that inside the "main" method in this case, "args[0]" contains "foo", "args[1]" contains "bar", and "args[2]" contains "hippo".
    Now go back to the example and see how it lines up with that.

  • 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() problem with Linux

    Hi All,
    I have a java program which I am using to launch java programs on all platforms.
    I am using the Runtime.exec() method to start the process in a separate JVM.
    But, I had a problem with the -classpath switch if the directories contained spaces. So I modified the java command which I am passing to the exec() method to something like:
    java -classpath \"./my dir with spaces\" com.harshal.MainThis I had to do because of the problem in windows. But, if I use double quotes in Linux (for the classpath switch in my exec() method), it won't work.
    Can anyone correct me so that I can use the Runtime.exec() method on all platforms to launch the java application even if the classpath directories contains spaces.
    Thank you very much.

    I was reading about the command line args on java's
    tutorial and I found a shocking news. Mac OS doesn't
    support command line args, That's news to me. Could you please elaborate ?
    More important is: I got it working. I figured out I had forgotten to try something before, or, to be more correct, I made an error when trying malcommc's envp suggestion: I used "classpath" as key, not "CLASSPATH", as it should have been.
    Ran a new test, got it working.
    Sample:
    Given a rootdir. Subdirectory "cp test" with a classfile (named "test") without package declaration. Running another class in another directory, using:
    String[] cmd = new String[]{
        "java", "test"
    String[] envp = new String[]{
        "CLASSPATH=rootdir:rootdir/cp test" // <-- without quotes.
    Runtime.getRuntime().exec(cmd, envp);It's been my wrong all the time. I didn't check hard enough. It simply had to work somehow (that's the kind of things that's easy to say afterwards :-)).

  • Runtime exec problem to execute a C program

    Hi,
    I've spend lot of time trying to find a solution without success...
    My aim is to run a C program from a java application under linux. My C code is the following:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    main(int argc, char **argv){
    printf("hello world \n");
    Once compiled I run my java application wich run the binary through a runtime.exec().
    I followed the example given by
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    with the same input gobblers and threads.
    For some reason it doesn't work: nothing comes out...
    When I call "ls" instead of my binary it works perfectly!
    WHY??
    Any help would be greatly appreciated!

    Thanks for the reply.
    Yes it seems that JNI could be a solution, but it looks a bit complicated an maybe not so well adapted to my purpose.
    The executables I want to execute from my java application don't need any arguments.
    If JNI is really the only way I'll try to use it but is there any good reason why runtime exec doesn't work? It is supposed to execute any executable isn't it?
    cheers

  • Process/runtime.exec() problem

    i m trying to compile and run java files thru runtime.exec()...i m working on linux...when i compile a singe file it works all right....however when i compile multiple files using the same command only replacing "filename.java" by "*.java" its not working.
    error: cannot read: /home/pico/example/demo/*.java
    1 error
    any help will be appreciated

    I doubt, *.java will get replaced automatically with all your java-files. It's just treated as as file called "*.java", because resolving the wildcard is usually done by a shell which is not running when using Runtime.exec().
    You have to (re)solve it yourself.
    Hope this helped.

  • Runtime.exec problem

    we have a c program which does the encryption on the input files.
    IF we ran this program in unix os, it will take 30 secs to finish.
    But if we call this program using java by calling Runtime.getRuntime().exec(command)
    it takes 20 minutest to finish.
    We wonder why does it take this much time to finish.
    We are having thought that when the program runs in unix os it can get all the resources it want.
    but when run this through java, it is limited to JRE / JVM memory size. --->Am I right?
    Could you please clarify my doubt on the memory size. If I wrong, how can we fix this problem.
    Thanx

    In the case of unix
    u will just run the executable using a.out. For processor its just the execution of the executable, so 30 secs
    In case of java
    step1: It has to interpret the java program line by line after doing required loading, linking and initialization
    of the required libraries and class files.
    step2: It has to create a separate process using Runtime.getRuntime().exec() and wait for the result
    of that process
    so the total time will be step1 + step2 = some time + 30 sec = 20 minutes.

  • Runtime.exec() - Problem when using cvs-command

    I have a problem with the Runtime.getRuntime().exec() - Command. I try to execute a command to export files from our cvs-repository. As you hopefully know, cvs produces a lot of output.
    When I start my 'cvs export ... '- command from the console-window of windows, everything works perfect. But when I try to use the Runtime.getRuntime().exec("CVS export ...") the created cvs-subprocess stops after the export of the first three files. When I close the main-window, where the cvs-process was started from, the cvs-process continues working.
    I could see, that many others had the same problem, but I couldn't find a real solution there.
    Is there a possibility to clear/delete the output-buffer of the cvs-subprocess, because I don't really need the information, that cvs gives me. It is enough for me when cvs stores the files :-)
    My source:
    public void executableTest()
    Runtime run = Runtime.getRuntime();
    try
    Process cvsProcess = run.exec("cvs export .... ");
    cvsProcess.waitFor();
    BufferedReader in = new BufferedReader
              ( new InputStreamReader(cvsProcess.getInputStream()) );
         String line;
         while ((line = in.readLine()) != null)
              System.out.println(line);
         catch (Exception e)
         System.out.println(e.getMessage());
    Thanks for your help.

    if the buffer is overflowing, then you don't want to do the waitfor until after you've hit the end of the inputstream, me thinks.

  • Runtime exec() Problem, change working dir

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

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

  • Runtime.exec Problem with setting environment

    Hello
    I will run a command with a new process environment. As example I take "ls". If I use the "exec(String)" method it works fine (like it should; my PATH is ...:/usr/bin:...).
    Next when I use "exec(String cmd, String[] env)" with cmd = ls and env = {PATH=} then the programm also prints out the listing of the current directory. In my opinion this shoudn't work.
    I have the problem using jdk1.2.2 (Solaris VM (build olaris_JDK_1.2.2_10, native threads, sunwjit)) on Solaris 8.
    As I understand the exec the method should work like this:
    1. fork a new Process
    2 set environment for the new process
    3 exec the new Programm in this process
    Is this statement right?
    On Solaris 2.6 the program works fine and I get an IOException.
    Some hints way the env for the process isn't set?
    Thanks
    ========================================================
    import java.io.*;
    public class Test {
    /** Version der Klasse. */
    public static final String VERSION = "$Revision:$";
    public static void main(String[] arg) {
    try {
    call("ls", new String[]{"PATH="});
    } catch (Exception ex) {
    System.out.println(ex);
    private static void call(String cmd, String[] env)
    throws Exception
    Runtime rt = Runtime.getRuntime();
    try {
    System.out.println(cmd);
    Process p = rt.exec(cmd, env);
    StreamGobbler errorGobbler = new
    StreamGobbler(p.getErrorStream(), "ERROR", System.err);
    StreamGobbler outputGobbler = new
    StreamGobbler(p.getInputStream(), "OUTPUT", System.out);
    errorGobbler.start();
    outputGobbler.start();
    try {
    p.waitFor();
    } catch (InterruptedException e) {
    if (p.exitValue() != 0) {
    throw new Exception("Process failed");
    } catch (IOException ex) {
    System.out.println("IOException: " + ex.toString());
    class StreamGobbler extends Thread {
    private InputStream m_input;
    private OutputStream m_output;
    private String m_type;
    private StringBuffer m_message;
    StreamGobbler(InputStream is, String type, OutputStream os) {
    this.m_input = is;
    this.m_output = os;
    this.m_type = type;
    this.m_message = new StringBuffer();
    outputGobbler.start();
    try {
    p.waitFor();
    } catch (InterruptedException e) {
    if (p.exitValue() != 0) {
    throw new Exception("Process failed");
    } catch (IOException ex) {
    System.out.println("IOException: " + ex.toString());
    class StreamGobbler extends Thread {
    private InputStream m_input;
    private OutputStream m_output;
    private String m_type;
    private StringBuffer m_message;
    StreamGobbler(InputStream is, String type, OutputStream os) {
    this.m_input = is;
    this.m_output = os;
    this.m_type = type;
    this.m_message = new StringBuffer();
    public synchronized void run() {
    try {
    InputStreamReader reader = new InputStreamReader(m_input);
    BufferedReader bufferedReader = new BufferedReader(reader);
    PrintWriter writer = new PrintWriter(m_output, true);
    String line = null;
    while ( (line = bufferedReader.readLine()) != null) {
    writer.println(m_type + "> " + line);
    this.m_message.append(m_type + "> " + line + "\r\n");
    } catch (IOException ioe) {
    ioe.printStackTrace();
    public synchronized String getMessage() {
    return this.m_message.toString();

    I'm having the same problem...
    Have you been able to solve your problem yet?

  • Runtime.exec lifecycle

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

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

  • Problem in Runtime.exec()

    I am trying to launch a new java application from my java program like this-:
    import java.io.*;
    public class test123{
    //String userStr="";
                public static void main(String args[]) throws Exception{
                        Process p = Runtime.getRuntime().exec("java JavaExec",null,currentDir);
                        Thread.sleep(10000);
                        System.out.println("After Destroy");
    } The JavaExec file�s code is -:
    import java.io.*;
    import org.apache.log4j.Logger;
    public class JavaExec
                 static Logger logger = Logger.getLogger("JavaExec.class");
    public static void main(String args[])
    try
                Runtime runtime = Runtime.getRuntime();
                            Process process = runtime.exec("notepad");
                int exitCode=0;
                while(true)
                            //logger.info("Inside the infinite while loop in javaexec");
                            try
                                        exitCode = process.exitValue();
                                        System.out.println(exitCode);
                                        process.destroy();
                                        process = runtime.exec("notepad");
                            catch(IllegalThreadStateException itse)
                                        System.out.println("Inside exception");
    } catch (Throwable t)
    t.printStackTrace();
    }Notepad opens when I execute the test123 class but instead of remaining open even if I close it , I am able to close notepad. The JavaExec only starts processing again when my main quits.
    Please let me know the solution to this problem.....
    Thanks in Advance
    Inder Jeet Singh

    Convoluted at best. You don't need that loop, just useexitCode = process.exitValue();and it will block until notepad exits.
    P.S. Why a Runtime.exec() executing a Java program that does a Runtime.exec() on notepad?

  • Problem with runtime.exec().It hangs Up

    Hi all,
    I am having a problem with the runtime.exec method.I am trying to execute linux commands using this method.For most of the commands it works fine.But when i tried to change the user with the su command in linux my program hung up.So please help me to get around this.any help would be highly appreciable..
    I am pasting the code..
    <code>
    Process p=null;
    int ch=0;
    try
    System.out.println("Before executing command");
    String unlock_command="sh changeuser.sh";
    p = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c","su tony"});
    InputStreamReader myIStreamReader = new InputStreamReader(p.getInputStream());
    while ((ch = myIStreamReader.read()) != -1)
    System.out.print((char)ch);
    p.waitFor();
    int p_exitvalue = p.exitValue();
    System.out.println("After executing the command and the exit value = "+p_exitvalue);
    p.destroy();
    catch (IOException anIOException)
    System.out.println(anIOException);
    catch(Exception e)
    e.printStackTrace();
    </code>
    Thanks
    HowRYou

    Hi sabre,
    What you have pointed out is right.But if i change the user as root then it will not ask for a password.Isn't it.Anyway thank you for giving your suggestions.Can yoiu help me more.Waiting for all of your help.I will try to swoitch between different users othere than root by giving the password.So just help me.

  • Runtime.exec() batch file problem

    Hi folks,
    i have a little problem when I want to execute a batch file through java's runtime.exec() method.
    the execution of a very simple batchfile works (for example opening notepad or other stuff), but I have problems with the following batch file (although it's still simple):
    net use s: \\Dd-nt-fs\Dsmp15_files
    set DSCFG=c:\dscfg
    set PSPATH=c:\adproof
    set ora_path=C:\oracle\ora92
    set path=S:\Dsmp_Q4_2004\Bin;%ora_path%\bin;%path%;
    set nd_font=S:\Dsmp_Q4_2004\Fonts
    set nxPS_FONT_DIR=%ND_FONT%
    set PSPATH=c:\adproof
    set PSFORMS=S:\Dsmp_Q4_2004\PsForms\Telenor
    s:
    cd S:\Dsmp_Q4_2004\bin
    S:\Dsmp_Q4_2004\Dsmp_Reports\Telenor\adproof.exe DBUSER=a_user DBPSWD=a_pswd DBSTR=dbstr ADINFO=adinfo.lst TASKID=a_taskid
    my guess is that there is a problem with the setting of environment variables which correspond to the drive s:
    I mannually added the batchfile (line by line) and looked whether it got through to the command which executes the adproof.exe file: for example the below batchfile worked:
    set DSCFG=c:\dscfg
    set PSPATH=c:\adproof
    set ora_path=C:\oracle\ora92
    s:
    cd S:\Dsmp_Q4_2004\bin
    S:\Dsmp_Q4_2004\Dsmp_Reports\Telenor\adproof.exe DBUSER=a_user DBPSWD=a_pswd DBSTR=dbstr ADINFO=adinfo.lst TASKID=a_taskid
    Here is the java code: in which i execute the batch file:
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("net use s: \\\\Dd-nt-fs\\DSMP15_FILES");
    BufferedReader  b = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
    while( (line=b.readLine())!=null) {
          System.out.println(line);
    int exitVal = proc.waitFor();
    System.out.println("Exit Value = "  + exitVal);
    String[] cmd = new String[1];
    cmd[0] = "C:\\Documents and Settings\\tikmi\\My Documents\\mysources\\DSMP Prototype\\print\\hallo3.bat";
    // here i declared the needed settings of the environment variable and pass that array to the exec() method                   
    String[] env = new String[8];
    env[0] = "DSCFG=c:\\dscfg";
    env[1] = "ORA_PATH=C:\\oracle\\ora92";
    env[2] = "PSPATH=C:\\Documents and Settings\\tikmi\\My Documents\\mysources\\DSMP Prototype\\print";
    env[3] = "ND_FONT=S:\\Dsmp_Q4_2004\\Fonts";
    env[4] = "nxPS_FONT_DIR=%ND_FONT%";
    env[5] = "PSFORMS=S:\\Dsmp_Q4_2004\\PsForms\\Telenor";
    env[6] = "ND_PATH=S:\\Dsmp_Q4_2004\\resource";
    env[7] = "PATH=S:\\Dsmp_Q4_2004\\Bin;%ORA_PATH%\\BIN;%ND_PATH%;%PATH%;";
    rt  = Runtime.getRuntime();
    proc = rt.exec(cmd, env);
    b = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
    while( (line=b.readLine())!=null) {
              System.out.println(line);
    exitVal = proc.waitFor();
    System.out.println("Exit Value = "  + exitVal);Maybe someone else had similar problems or can help me solving that problem.
    Any advice would be very appreciated.
    regards
    mirkolino

    finally I got it working now.
    for those who are interested in the problem, my code that's now working is the following
    Runtime rt = Runtime.getRuntime();
                            Process proc = null;
                            String cmd = "cmd.exe /c c:\\adproof\\hallo3.bat";
                            proc = rt.exec(cmd);
                            InputStream in = proc.getInputStream();
                            BufferedReader br = new BufferedReader ( new InputStreamReader(in));
                            String line;
                            while( (line=br.readLine()) != null) {
                                System.out.println(line);
                            int exit = proc.waitFor();
                            System.out.println();
                            System.out.println("Process exited with: " + exit);the problem was, that i have to handle and read the input stream
    thanks for you help
    greetings from mirkolino

Maybe you are looking for

  • Custom Panel UI

    I'm developing for AE CS3 on Windows. Is it possible to create my own panel UI through the C++ interface? I've found how to do it with the ScriptUI system, which is pretty slick, but the functionality I'm working on is a bit big, hairy, and scary to

  • Updated ITunes and now it won't coonect to the internet

    Please help..... I updated my ITunes on my computer on Saturday and ever since I get an error message saying that "ITUNES COULD NOT CONNECT TO THE MUSIC STORE. THE NETWORK CONNECTION WAS REFUSED. MAKE SURE YOUR NETWORK SETTINGS ARE CORRECT AND YOUR N

  • WRVS4400N needs to be rebooted every 24 hours

    I have the latest firmware and I have reset to factory defaults but I still need to reboot the router every 24 hours. Can anyone help?

  • AD Built-In groups that should be avoided as best practice

    I am on a 2008r2 domain.  I spoke to a security engineer from Microsoft a few years ago.  He mentioned some known issues that can occur from using some of the built-in security groups like Account Operators, Backup Operators, Server Operators, etc. I

  • Where to find the logs for cronacle queues

    hi i m using redwood explorer 7.0.3 . Someboday had hold the cronacle queues . it was giving the message queues held by operator . But we don't know who held the queues. Can anbody tell where we can find the logs for these queues i.e who made changes