How to execute .bat file through java?

I already create a batch file to pull & push file. Now, i want to execute this .bat file java.I got this example but it doesnt work. Did i missed something or do we have the better one?
import java.lang.*;
import java.io.*;
public class Loadfile
public static void main(String args[]) throws IOException
Runtime load = Runtime.getRuntime();
r.exec("C:\\pull.bat");
}

For Runtime,i'd change it to:
Runtime load = Runtime.getRuntime();
        String cmd = "C:\\javaclass\\copytemp.bat";
        Process proc = load.exec(cmd.toString());Is it right? But still can't work.
Here is the .bat file:
@echo off
c:
cd "c:\Inetpub\ftproot\Debitin"
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo open localhost
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo Administrator
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo password
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo cd ftpScript
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo binary
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo lcd C:\
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo lcd "C:\Inetpub\ftproot\infile"
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo prompt n
pause
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo mget *.txt::@rem >> C:\Inetpub\ftproot\Logrecord\pullscript.txt echo mdel *.*
C:\Inetpub\ftproot\Logrecord\pullscript.txt echo byeftp.exe -s:C:\Inetpub\ftproot\Logrecord\pullscript.txt
::del C:\Inetpub\ftproot\Logrecord\pullscript.txt
pause
exit
[\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • How to execute ".exe" files using java

    Hi,
      This is guruvulu,
         I have a problem in executing ".exe" files.For Example InternetExplorer.

    Hi,
    You can execute .exe files in JAVA using the following code.
    Runtime rt1 = Runtime.getRuntime();
    Process pc = rt1.exec("someexe.exe");
    you can get the output of the executed exe file in
    in = pc.getInputStream(); //this returns a InputStream
    hope this solves your problem.
    regards,
    P.Venkat

  • How to execute *.BAT file from  the Java Application

    Hello to all.
    I wants to run *.BAT file form my applicaion.
    Can u give the code of that two-four line,please
    Wating four your replay.
    Yours Friend
    Bhavin Shah.....

    pr = rt.exec("cmd.exe /c start " + yourProgramName)The exec() method executes the command you specify in the argument and returns a process. In this example, it's telling Windows to run "yourProgramName".
    HTH

  • 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]

  • How to execute jar file in java project

    hi,
    i have made a proj in java in which i have put all my files in a jar file.
    can somebody help me how to execute this jar file??
    thanks

    u can put that jar file in ur class path,,
    regards
    shanu

  • How to execute .bat file within pl/sql block

    Hi,
    I want to execute a batch file (.bat) file withing a pl/sql procedure. Please guide me for it.
    Regards

    There are several possible ways to make a call-out from a PL/SQL program to the OS on the database server (but not to the client computer).
    You could use java or an external procedure (you'll need to code it in C) for example.
    You might be able to make use of UTL_HTTP to talk HTTP to another server or UTL_TCP to talk TCP to another server.
    What is it you are trying to do?

  • Error : How to execute *.BAT file

    Some of the friend said me to execute any file following code
    Runtime rt=Runtime.getRuntime();
    Process pr=null;
    pr = rt.exec("cmd.exe /c start " + "myfilename");
    I get error as
    CreateProcess: cmd.exe /c start myfilename error=0
    Press any key to continue . . .
    what is cmd.exe /c start in exec().
    Thanks..

    hi Bhavin
    try this code because i had the same problem an d this thing works for me here is the code
        // Get file name
        String File_Name = // What ever yr file name get as String
        // Get Operating System Name
        String os_name = System.getProperty("os.name");
        os_name = os_name.toUpperCase();
        // Declare command as array of string
        String[] command ;
        // on Windows XP, NT, 2000 command is different and on win 98, 95 is different
        if(os_name.indexOf("XP") != -1){
             command = new String[] {"cmd", "/C", "start", "\"\"", File_Name};
        else if(os_name.indexOf("NT") != -1){
             command =new String[] {"cmd", "/C", "start", "\"\"", File_Name};
        else if(os_name.indexOf("2000") != -1){
             command = new String[] {"cmd", "/C", "start", "\"\"", File_Name};
        else  {
             command = new String[] {"start", "\"\"", File_Name};
        try
            // Run the commands using Runtime
            Process process = Runtime.getRuntime().exec(command);
        catch(IOException ioe)
            //show Error message
                  JOptionPane.showMessageDialog((Component) null,
                                          "Unable to Locate the file..."+
                                          "\n"+ioe.getMessage(),
                                          "Error...",
                                          JOptionPane.ERROR_MESSAGE);
        }Regards
    Satinderjit

  • How to execute batch files in java

    Hi,
      I am trying to execute a batch file using a java program(StopServer in sdm).But i am not able to execute it.

    Greetings.
    You may read this article (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)
    to avoid of getRuntime().exec() traps.

  • How to execute Bat Files using Jobs?

    Hello, can anyone help me?
    I have created a job like this, but it's not working:
    begin
    dbms_scheduler.create_job(
    job_name => 'job_test'
    ,job_type => 'EXECUTABLE'
    ,job_action => 'C:/temp/test.bat'
    ,start_date => '01/DEC/2006 08:30 AM'
    ,repeat_interval => 'FREQ=DAILY'
    ,enabled => TRUE
    ,comments => 'Demo for job schedule.');
    end;
    begin
    DBMS_SCHEDULER.run_job (job_name => 'job_test',use_current_session => false);
    end;
    Thx!

    Hi,
    This will not work because a batch file is not directly executable. It is executed using cmd.exe .
    So what you need to do is to set c:\windows\...\cmd.exe as the job_action and then as your arguments set
    /q
    /c
    c:\test.bat
    then enable the job. This should work.
    Also make sure the job scheduler service is setup and started (it needs to be started for external jobs to run).
    There is an example given by scotttig in this thread
    Re: dbms_scheduler
    Hope this helps,
    Ravi.

  • Error while running executable file through java in WinNT

    I would like to run an executable file with Java.
    - If I try with notepad or paint, i.e. Windows Applications,
      I have no problem.
    - I also can run Non-Windows-Own Applications, except one.
      I get an error message, if I want to run this program through Java.
    I have tried following commands to run an executable file.
    Runtime.getRuntime().exec("cmd.exe /c "+command);
    Runtime.getRuntime().exec("cmd.exe /c start "+command);
    Runtime.getRuntime().exec("cmd.exe /c start /wait "+command);
    Runtime.getRuntime().exec("cmd.exe /k start "+command);
    command : the path to the executable file
    I can run the application directly, if I click the icon on desktop,
    but not through Java.
    here is the error message I get
    screenshot : http://www.aykut.de/error_message.jpg
    Text : "Security Check failure"
            The Logon System has been tampered with.
            The Administrator will need to re-install.
    my Idea :
    The application is "old".
    I think it was written for Win 3.1.
    Therefore I don't know if there is any other
    possibilty to run a "DOS Exe File" through Java.

    I have just figured out how it works,
    if somebody else here in forum have this problem,
    here is the solution :
    String path = "F:\...\...\Application.exe";
    String envDir = path.substring(0, path.lastIndexOf("\\"));
    String[] command = {"cmd.exe", "/c", "start", "/wait", "/D"+envDir, path};
    Process process = Runtime.getRuntime().exec(command);
    "start /Dpath" => path: environment directory F:\...\...\
    "start /wait" => wait until Application.exe terminates
    if you use Win95 or Win98 use command.com instead of cmd.exe
    Aykut

  • Hot to call  forms11g  fmx file  through Java executable

    Hi,
    Iam having one file in some folder which will come through FTP , whenever file comes to the folder i should call the some form fmx file through JAVA so that my form will take care rest of the things .
    My question is how to call fmx through Java executable in windows environment.
    thanks in advance
    GV

    Hi All,
    Thnaks for the Info. But my requirement is different.
    1) whenever i received a file through FTP from other server to my server , some folder say d:\Test
    a) some batch program has to trigger and first it should take the backup of the received file to some other folder say d:\archive
    b) some batch program has to trigger to call the forms fmx file so that form will take care of reading from the file and put the data to database for the received file in d:\Test.
    Assume that it is in windows environment/Linux Environment . How i can achieve these tasks. There should not any user intervention in this , everything is automatic.
    Please guide me any solutions
    Thanks in advance
    GV

  • How to call a .bat file from java code?

    How to call a .bat file from java code? and how can i pass parameters to that .bat file?
    Thanks in advance

    thanks for ur reply
    but still i am getting the same error.
    I am trying to run a .bat file of together tool, my code looks like below
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.File;
    class SysCall{
         public static void main(String args[]){
              String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
              //String path="D://Borland//Together6.2//bin//Together.bat ";
              Runtime r= Runtime.getRuntime(); //Declare the system call
              try{
                   System.out.println("Before batch is called");
                   Process p=r.exec(cmd);
                   System.out.println(" Exit value =" + p.exitValue());
                   System.out.println("After batch is called");
              /*can produce errors which must be caught*/
              catch(Exception e) {
                   e.printStackTrace();
                   System.out.println (e.toString());
    I am getting the below exception
    Before batch is called
    java.lang.IllegalThreadStateException: process has not exited
    at java.lang.Win32Process.exitValue(Native Method)
    at SysCall.main(SysCall.java:17)
    java.lang.IllegalThreadStateException: process has not exited

  • How to get the source code of an HTML page in Text file Through java?

    How to get the source code of an HTML page in Text file Through java?
    I am coding an application.one module of that application is given below:
    The first part of the application is to connect our application to the existing HTML form.
    This module would make a connection with the HTML page. The HTML page contains the coding for the Form with various elements. The form may be a simple form with one or two fields or a complex one like the form for registering for a new Bank Account or new email account.
    The module will first connect through the HTML page and will fetch the HTML code into a Text File so that the code can be further processed.
    Could any body provide coding hint for that

    You're welcome. How about awarding them duke stars?
    edit: cheers!

  • Executing bat file without using Runtime.exec()??

    Hi all
    From my java App ,I am running a bat file. This is what I did:
    When I press 'execute' button inside my App, it runs a bat file through Runtime.exec() method. Since exec() runs it through cmd.exe, get a DOS window when I press Execute button. If I manually runs my app from command promt , I dont get it. But I have to create a short cut of my main class in the desktop. This is happening when I run my app from desktop icon.
    Now I want to eleminate DOS popup everytime I press execute button. Would anyone pls give an idea how to run bat file without using Runtime.exec()? Any suggestion will be helpful.
    Thanks

    jscell
    Thanks for taking time to answer to my problem .
    Here is what my problem: I create a shortcut of my main class in the desktop. Through this shortcut ,I run my java App. My App has a execute button, When I press this button , It run another bat file through Runtime.exec() method, and show some result in the result PAnel. NOw what happen , I get a DOS command window , everytime I press execute button. , Which is very annoying . But If I run my App thorugh command promt by executing: "java myApp", then I dont get this DOS popup. But I have to create a shortcut in the desktop, so other can use it conveniently.
    NOw I am not sure why I am getting this DOS window in the middle of my Application. IS it for using Runtime.exec() method? or for running bat file through my application? Can anyone pls tell me? I am kind of new to java, and I am learning lot of stuff from this forum .
    Would u pls suggest me about how to eleminate this DOS popup when I press execute button.
    Regrds

  • Executing batch file from Java stored procedure hang

    Dears,
    I'm using the following code to execute batch file from Java Stored procedure, which is working fine from Java IDE JDeveloper 10.1.3.4.
    public static String runFile(String drive)
    String result = "";
    String content = "echo off\n" + "vol " + drive + ": | find /i \"Serial Number is\"";
    try {
    File directory = new File(drive + ":");
    File file = File.createTempFile("bb1", ".bat", directory);
    file.deleteOnExit();
    FileWriter fw = new java.io.FileWriter(file);
    fw.write(content);
    fw.close();
    // The next line is the command causing the problem
    Process p = Runtime.getRuntime().exec("cmd.exe /c " + file.getPath());
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = input.readLine()) != null)
    result += line;
    input.close();
    file.delete();
    result = result.substring( result.lastIndexOf( ' ' )).trim();
    } catch (Exception e) {
    e.printStackTrace();
    result = e.getClass().getName() + " : " + e.getMessage();
    return result;
    The above code is used in getting the volume of a drive on windows, something like "80EC-C230"
    I gave the SYSTEM schema the required privilege to execute the code.
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    GRANT JAVAUSERPRIV TO SYSTEM;
    I have used the following to load the class in Oracle 9ir2 DB:
    loadjava -u [system/******@orcl|mailto:system/******@orcl] -v -resolve C:\Server\src\net\dev\Util.java
    CREATE FUNCTION A1(drive IN VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'net.dev.Util.a1(java.lang.String) return java.lang.String';
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    The problem that it hangs when I execute the call to the function (I have indicated the line causing the problem in a comment in the code).
    I have seen similar problems on other forums, but no solution posted
    [http://oracle.ittoolbox.com/groups/technical-functional/oracle-jdeveloper-l/run-an-exe-file-using-oracle-database-trigger-1567662]
    I have posted this in JDeveloper forum ([t-853821]) but suggested to post for forum in DB.
    Can anyne help?

    Dear Peter,
    You are totally right, I got this as mistake copy paste. I'm just having a Java utility for running external files outside Oracle DB, this is the method runFile()
    I'm passing it the content of script and names of file to be created on the fly and executed then deleted, sorry for the mistake in creating caller function.
    The main point, how I claim that the line in code where creating external process is the problem. I have tried the code with commenting this line and it was working ok, I made this to make sure of the permission required that I need to give to the schema passing security permission problems.
    The function script is running perfect if I'm executing vbs script outside Oracle using something like "cscript //NoLogo aaa1.vbs", but when I use the command line the call just never returns to me "cmd.exe /c bb1.bat".
    where content of bb1.bat as follows:
    echo off
    vol C: | find /i "Serial Number is"
    The above batch file just get the serial number of hard drive assigned when windows formatted HD.
    Same code runs outside Oracle just fine, but inside Oracle doesn't return if I exectued the following:
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    Never returns
    Thanks for tracing teh issue to that details ;) hope you coul help.

Maybe you are looking for

  • Macbook Pro fails on startup after drive format and OSX reinstall

    Hi all,      I have a 2012 15'' Retina Macbook Pro - pretty new, so it surprises me I'm having this issue.      The problem was pretty sudden - one day upon startup, I would be immediately told that Finder has closed unexpectedly. From this point on,

  • Transfer the data from old to sap db

    hi, i  having ten thoused records in legacy system , but i want to transfer only 2000 records at a time , how can we do that

  • Can't See Files On Remote Server

    Wondering if anyone has a fix for not seeing files on remote server... It's even got my host stumped. I have a fairly large static site which I CAN SEE files via my host's "File Manager" 90 Folders 3090 Files 52,336.74KB But I cannot see files and fo

  • Sharing address book contacts

    Hello We run a small network (less than 10 users) and run mail, file & user services off Mac OS X Server 10.4.x. I will probably upgrade to Leopard Server when available. I need to find a way of sharing address book information amongst our users. Thi

  • Why do i keep getting a 13019 error code?

    i keep getting a 13019 error code when i try to sync my ipod to itunes?? I did a hard reboot and now it won't even turn on. Please help!