How to invoke dos shell from java program

Hi,
I'm not able to invoke dos shell from java.
Can any one help me in this issue.
I'm providing the source code below:
try{
Runtime.getRuntime().exec("cmd.exe")
catch(IOException e) {
System.out.println(e.getStackTrace());
Thanks

Does it throw a different exception?
Or does it just do nothing at all?
It does nothing at all[/b
Is this a standalone Java app?
Or a Java Applet running via a webbrowser? [b]It's a standalone application

Similar Messages

  • Invoking dos commands from java

    hi all,
    I just want to invoke dos prompt from java.I know it can be done using "Runtime.getRuntime()" command.But when i try to create a directory inside another directory,how can i specify the path of the destination directory.i googled as well as tried different things.But i failed to make it up.Please help me solve this problem.
    thanks in advance
    Regards

    Hai,
    Thanks for your respond.
    If I give "cmd" command only, I am getting dos command window, but I didn't get the prompt like
    c: or d:
    How can I do it?
    Expecting more helps
    Joseph

  • How to invoke BPEL process from JAVA API

    Hi Guys
    Any idea if you can tell me how to invoke BPEL process from JAVA API ?
    What to do in BPEL process manager to achieve that?
    Regards
    Deepak

    See http://download-west.oracle.com/docs/cd/B31017_01/integrate.1013/b28981/invoke.htm#sthref1373 and the JavaDocs http://download-west.oracle.com/docs/cd/B31017_01/integrate.1013/b28986/toc.htm.

  • How to execute dos command in Java program?

    In Perl, it has System(command) to call dos command.
    Does java have this thing?
    or any other way to execute dos command in java program?
    Because i must call javacto compile a file when the user inputed a java file name.

    Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
    exec(String command) that will execute that command in a dos shell.
    Regards,
    Gerrit.

  • Problem while running dos command from java program

    Dear friends,
    I need to terminate a running jar file from my java program which is running in the windows os.
    For that i have an dos command to find process id of java program and kill by using tskill command.
    Command to find process id is,
    wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
    This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
    when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
    Code to run this command is,
    public class KillProcess {
         public static void main(String args[]) {
              KillProcess kProcess = new KillProcess();
              kProcess.getRunningProcess();
              kProcess = new KillProcess();
              kProcess.readProcessFile();
         public void getRunningProcess() {
              String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
              try {
                   Runtime run = Runtime.getRuntime();
                   Process process = run.exec(cmd);
                   int i = process.waitFor();
                   String s = null;
                   if(i==0) {
                        BufferedReader stdInput = new BufferedReader(new
                               InputStreamReader(process.getInputStream()));
                        while ((s = stdInput.readLine()) != null) {
                         System.out.println("--> "+s);
                   } else {
                        BufferedReader stdError = new BufferedReader(new
                               InputStreamReader(process.getErrorStream()));
                        while ((s = stdError.readLine()) != null) {
                         System.out.println("====> "+ s);
                   System.out.println("Running process End....");
              } catch(Exception e) {
                   e.printStackTrace();
         public String readProcessFile() {
              System.out.println("Read Process File...");
              File file = null;
              FileInputStream fis = null;
              BufferedReader br = null;
              String pixieLoc = "";
              try {
                   file = new File("ProcessList.txt");
                   if (file.exists() && file.length() > 0) {
                        fis = new FileInputStream(file);
                        br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
                        String line;
                        while((line = br.readLine()) != null)  {
                             System.out.println(line);
                   } else {
                        System.out.println("No such file");
              } catch (Exception e) {
                   e.printStackTrace();
              return pixieLoc;
    }     when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
    if i give process.waitFor(), then it's in running mode and program is not completed.
    Colud anyone please tell me how to handle this situation?
    or Is there anyother way to kill the one running process in windows from java program?
    Thanks in advance,
    Sathish

    Hi masijade,
    The modified code is,
    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, "UTF-16");
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    System.out.println(type + ">" + line);
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    public class GoodWindowsExec
        public static void main(String args[])
            try
                String osName = System.getProperty("os.name" );
                String[] cmd = new String[3];
                 if( osName.equals( "Windows 95" ) )
                    cmd[0] = "command.com" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                } else {
                    cmd[0] = "cmd.exe" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd[0] + " " + cmd[1]
                                   + " " + cmd[2]);
                Process proc = rt.exec(cmd);
                System.out.println("Executing.......");
                // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERROR");           
                          // any output?
              StreamGobbler outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUTPUT");
                          // kick them off
                errorGobbler.start();
                outputGobbler.start();
                // any error???
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
            } catch (Throwable t)
                t.printStackTrace();
    }when i execute the above code, i got output as,
    Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
    and keeps in running mode only.
    If i execute the same command in dos prompt,
    CommandLine
    ProcessId
    java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP  2468
    If i modify the command as,
    cmd.exe /C wmic process where "name='java.exe'" get commandline,processid  > 123.txt
    and keeps in running mode only.
    If i open the file when program in running mode, no contents in that file.
    If i terminte the program and if i open the file, then i find the processid in that file.
    Can you help me to solve this issue?

  • How to Call .XDO file From Java Program

    Hi,
    I have developed a report in using BI Publisher version 10.1.3.
    I created the report and it only created XDO files. If I want to call XDO file from Java program how I can do that.
    What are the APIs available to do that.
    Thanks
    -Ashutosh

    Hi,
    the JavaAPI didn't work with the xdo-Files. But you can create a proxy stub for the Web Service API of BI Publisher which uses the xdo's in the repository.
    regards
    Rainer

  • How to approve the step from java program ?

    Hi all,
    I want to approve a step from java program.
    I call the store function "wf_notification.setattrtext" & "wf_notification.respond".
    It's not work.
    The notification's status become to 'CLOSE', but PO_REQUISITION_HEADERS_ALL.AUTHORIZATION_STATUS is 'IN PROCESS'.
    And I try to approve the flow from oracle web gui and it's OK !
    The notification's status become to 'CLOSE', but PO_REQUISITION_HEADERS_ALL.AUTHORIZATION_STATUS is 'APPROVED'.
    The java program as follows, and '1099999' is notification id.
    Can anyone please please please help me?
    Thanks, all.
    Gavin
    ===================================================================================================
    import java.util.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import javax.rmi.*;
    import javax.naming.*;
    import javax.sql.*;
    import java.sql.*;
    public class CommitPR
    public static void main(String[] aArgs) throws Exception
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@10.1.1.1:1521:ORA";
    String user = "user";
    String password = "password";
    Class.forName(driver).newInstance();
    String sql;
    Connection conn = null;
    Statement callStmt;
    conn = DriverManager.getConnection(url, user, password);
    conn.setAutoCommit(true);
    callStmt = conn.createStatement();
    sql = "{ CALL WF_NOTIFICATION.SETATTRTEXT ('1099999','RESULT','APPROVE') }";
    System.out.println("sql=" + sql);
    callStmt.execute(sql);
    sql = "{ CALL WF_NOTIFICATION.RESPOND ('1099999','ARRPOVED','EIP_ADMIN') }";
    System.out.println("sql=" + sql);
    callStmt.execute(sql);
    callStmt.close();
    conn.close();
    ===================================================================================================

    Hi,
    the JavaAPI didn't work with the xdo-Files. But you can create a proxy stub for the Web Service API of BI Publisher which uses the xdo's in the repository.
    regards
    Rainer

  • How to execute .msi files from java program

    Hi friends,
    i have written a java program which invokes and thereby execute any executable files like .exe and .bat.
    So its working fine with .exe and .bat files, but it is not working with .msi files.......can you please help me how can i execute .msi files as well??
    public class Executeexe {
         public static void main(String ar[])
              try
              Process p=null;
              Runtime rt=Runtime.getRuntime();
              p=rt.exec("D:\\mysql-essential-5.0.83-win32.msi");
              p.waitFor();
    catch(Exception e)
    }here is the program

    Make sure that the command that's being exec'd works from the cmd line.
    Then read this article and do what it says:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Then if you still are having problems explain what "...it is not working with .msi files..." really means, and provide a [SSCCE Example program|http://mindprod.com/jgloss/sscce.html]

  • Problems to execute "cd" DOS command from Java program

    Anyone try to exec command "cd.." or "cd directory", it doesn't have any action. No exceptions, just don't do anything.
    Runtime.getRuntime().exec("cd\\");
    Runtime.getRuntime().exec("cd hello");
    However, when I try the following, it is working fine. Any ideas???
    Runtime.getRuntime().exec("explorer");
    Runtime.getRuntime().exec("javac Test1.java");

    That's because cd is built into the command
    interpreter in Windows. Runtime.getRuntime().exec()
    can only be used to launch external programs. This
    article should get you going:And that's not the only reason why you can't do this.
    When you do
    Runtime.getRuntime().exec("cd c:\\");
    (or, heck, "cmd /c cd c:\\"): the new command that you spawn will cd to the destination specified, and then exit. The parent process (your java program, that is launching this command) won't go anywhere - the "cd" doesn't affect it.
    The only way to change your OS directory in Java is to invoke native code. And even then, the effects are undefined (in terms of how your CLASSPATH will be affected, etc.).

  • How to run sscript shell with java program

    Hi everybody,
    i want to know how can i do to execute a script shelle (bash) with program java (if it s possible)
    for example this script:
    #!/bin/bash
    echo "hello"
    can i run it with java program or i have to make dome modifications .
    thank you for your help in advance.

    Well, if you want to be portable across platforms, you should write as much code in Java as possible and not rely on native scripts (I'm sure your script is more complex than this 'echo' example ;-) ).
    Having said that, you can use the java.lang.Runtime class and in particular its various exec() methods.
    Try something like this:
    Process p;
    try {
        p = Runtime.getRuntime().exec("myscript.sh");
    } catch (IOException ioe) {
    }You can then "interact" with the spawned process with the Process object returned by the exec method.
    Note you need to have the appropriate security rights.
    For more details, look at the API documentation here:
    http://java.sun.com/j2se/1.4.2/docs/api/
    hth,
    -Alexis

  • How to execute system command from java program

    Hi all,
    I want to change directory path and then execute bash and other unix commands from a java program. When I execute them separately, it's working. Even in different try-catch block it's working but when I try to incorporate both of them in same try-catch block, I am not able to execute the commands. The change directory command works but it won't show me the effects of the bash and other commands.
    Suggestions??

    The code I am using is....
    try
    String str="cd D:\\Test";
    Process p=Runtime.getRuntime().exec("cmd /c cd
    "+str);your str string is already having cd in it but again you ar giving cd as part of this command also please check this,i will suggest you to remove cd from str
    Process p1=Runtime.getRuntime().exec("cmd /c mkdir
    "+str+"\\test_folder");you should say mkdir once you change your path,but here you are saying mkdir first and then cd D:\Test(this is because of str)..please check this
    Process p2=Runtime.getRuntime().exec("cmd /c bash");
    Process p3=Runtime.getRuntime().exec("cmd /c echo
    himanshu>name.txt");
    catch(IOException e)
    System.err.println("Error on exec() method");
    e.printStackTrace();
    Message was edited by:
    ragas

  • How to call msword application from java program

    hai every body
    i want to know about OLE in java.
    how can i invoke msoffice application in java code.
    if any body have sanple code for this post for me
    thank you

    There are some bridges available ...
    http://www.google.com/search?q=ole+java+bridge

  • How to invoke Bpel process  from java using 'bpel process WSDL'

    I want to call bpel process from java using bpel wsdl.
    could any one point me to any url/sample.
    Thanks
    Nagajyothy

    Hi Seshagiri,
    Thanks for providing links and initial steps to create web service proxy(using Jdeveloper 11g).
    I created a web service proxy.
    provided the needed inputs.
    when I ran the client app, bpel process(has a human task) got invoked but faulted with exception as below
    Operation 'initiateTask' failed with exception 'EJB Exception: : java.lang.ExceptionInInitializerError[[
         at oracle.tip.pc.services.common.ServiceFactory.getAuthorizationServiceInstance(ServiceFactory.java:147)
         at oracle.bpel.services.workflow.task.impl.TaskService.initiateTask(TaskService.java:1159)
         at oracle.bpel.services.workflow.task.impl.TaskService.initiateTask(TaskService.java:502)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
    please help me in solving the above problem.
    Thanks
    Nagajyothy

  • How to get oc4j version from Java program

    i have the following in my Java Program
    Runtime r = Runtime.getRuntime();
    Process p = r.exec("java -jar oc4j.jar –version");
    and then i try to read the InputStream from the Process p.
    but this line is not executing, it returns the following error.
    Unknown switch: ?version, type java -jar oc4j.jar -? for help
    if i change it to ----------
    Runtime r = Runtime.getRuntime();
    Process p = r.exec("java -jar $ORACLE_HOME/j2ee/home/oc4j.jar –version");
    then i get another error :
    Exception in thread "main" java.util.zip.ZipException: No such file or directory
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:112)
    at java.util.jar.JarFile.<init>(JarFile.java:127)
    at java.util.jar.JarFile.<init>(JarFile.java:65)
    but if i cd to /oracle/j2ee/home and then run the command java -jar oc4j.jar –version, then it gives me the right output with the right version, but for some reason the samething from inside the java program is giving me errors,
    please help. i just need to read the oc4j version running on the server and display it in JSP.

    Process p = r.exec("java -jar oc4j.jar –version");The character before "version" should be a hyphen; yours is not.
    Process p = r.exec("java -jar $ORACLE_HOME/j2ee/home/oc4j.jar –version");
    then i get another error : Exception in thread "main"
    java.util.zip.ZipException: No such file or directory
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:112)
    at java.util.jar.JarFile.<init>(JarFile.java:127)
    at java.util.jar.JarFile.<init>(JarFile.java:65)One more problem here: $ORACLE_HOME will be not be interpreted in the runtime.exec even if it is defined as an environment variable. So you get an error that tells you oc4j.jar is not found.
    Hope this helps you.

  • How to access system calls from java program?

    i am having a doubt regarding accessing system calls from a Java program like accessing unix system calls from a c program.

    Runtime.getRuntime().exec("line command here");
    example:
    Runtime.getRuntime().exec("ls -la");

Maybe you are looking for

  • Error message while using Photoshop Elements 9

    While using Photoshop Elements 9 I received the following error message: Font Capture: PhotoshopServer.exe application error. the instruction on 0x103e8453 refers to memory on 0x00000a74. The read & disk instruction ("read") on the memory has failed.

  • ROW_WID in fact tables.

    Hi, I notice that there are some fact tables with ROW_WID column. Some of the fact tables do not have this column. What is the purpose of having the ROW_WID in fact tables? Does anyone have an idea? I am using OBIA 7.9.5. Thanks. Manoj.

  • PI 7.31 - Component based alerting v/s Alert framework like 7.0

    PI Experts, We are in the process of upgrading PI from 7.0 to 7.31. In current PI-7.0, We are using Alert framework for notifying us for the failed messages in PI. PI-7.3 has the the new feature of Component based alerting, while implementation, we h

  • How to test BAPI_ACC_DOCUMENT_POST

    In FM BAPI_ACC_DOCUMENT_POST, one parameter is mandatory which is DOCUMENTHEADER having fields 6-7 mandatory fields out of which                  OBJ_TYPE (Reference procedure)                 OBJ_SYS (logical system)                 OBJ_KEY for thes

  • Material Master Data Reporting with SAP BW?

    Hello, I have a question regarding the use of a SAP BW System. Do you guys think SAP BW is a appropriate System for modelling and analysing Queries for the Material master data of the R/3 System. Focus:           Material master data Bill of Material