Running a batch file inside a jar

HI all
I created a jar file , in which i need to run a batch file , so i wrote a main class to execute the run the batch file , but when iam running the jar it is searching for the given batch file out side the jar.
my code is some thing like below
     public static void main(String args[])
          try
               Runtime rt=Runtime.getRuntime();
               Process process=rt.exec("%DIRNAME%/start.bat");
   InputStreamReader reader =
                  new InputStreamReader ( process.getInputStream () );
               BufferedReader buf_reader =
                   new BufferedReader (  reader );
                String line;
                while ((line = buf_reader.readLine ()) != null)
                             System.out.println (line);
          catch (IOException e) {
                System.out.println (e);
     }so please help me.. is it the problem in specifing the path...?
are does it have any other method to read the stream functions ..
thanks in advance
sam

I don't think this will work. You could not go to a command line and enter, "%DIRNAME%/start.bat" if start.bat was inside a jar - the CLI doesn't know how to read a batch file inside a jar.
I think it would work to programmatically read the lines of start.bat (when it is inside the jar) into an array of Strings and use Runtime.exec with the array as the argument.
It would also work to extract the start.bat file, then execute it using Runtime.exec.

Similar Messages

  • Running a Batch File on another Server with an Oracle Job

    hi, i have the following code
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
    job_name => 'test_job_bat',
    job_type => 'EXECUTABLE',
    job_action => '\\10.1.1.63\test\test.bat',
    enabled => true,
    comments => 'test bat'
    END;
    So i want to run a batch file, which lies on another pc in the network
    The code runs, without a failure.
    The bat file just contains "MD D:\bla" .
    When i run the code, no bla directory is created, so it seems that the batch file never ran.
    i approved read/write on the test folder. (Windows 7 machine)
    any ideas?
    Edited by: user1067632 on 31.05.2010 05:03
    in dba_scheduler_job_run_details the job is listed as FAILED:
    ORA-27370: Job-Unterprozess konnte einen Job vom Typ EXECUTABLE nicht starten
    ORA-27300: BS-abhängiger Vorgang accessing execution agent mit Status: 2 nicht erfolgreich
    ORA-27301: BS-Fehlermeldung: Das System kann die angegebene Datei nicht finden.
    ORA-27302: Fehler aufgetreten bei: sjsec 6a
    ORA-27303: Zusätzliche Informationen: Das System kann die angegebene Datei nicht finden.
    Edited by: user1067632 on 31.05.2010 05:16

    ok sorry, i made my testjob run, the OracleJobScheduler was not started.
    But now i ran into an another Problem.
    Now i want to java bla.jar in my batch, and got that new error
    ORA-27369: Job vom Typ EXECUTABLE nicht erfolgreich mit Exit-Code: Unzulässige Funktion.
    STANDARD_ERROR="Unable to access jarfile start.jar"
    anything to consider when accessing .jar files in my batch?
    edit:
    there was a classpath problem.
    Edited by: ginkgo on 01.06.2010 04:29

  • Running a batch file that calls my ear file

    hi, can anyone help out on this?
    i have a Schedule.class in my ear file (project.ear) and i need to write a batch file to run this class file inside the ear file. is this possible and if so, how shall my batch file looks? thanks in advance!

    thanx 4 replying
    but as i am a developer and i am developing the aplication for a client, so should i speak to the client for this or can i do this without interrupting them?
    -ashish

  • Running a batch file to invoke reports runtime

    Hi,
    I'd like to run a batch file at the end of every month automatically, which runs a report and sends the output in a mail. Is there a way to run this batch file without using cron job? We do not have unix environment at our place.
    ThanX.

    hello,
    on windows NT you have the AT functionality which is basic scheduling. however if you are using the oracle reports server you can schedule the report inside the server itself.
    regards,
    the oracle reports team

  • How to run a batch file as windows Nt service

    Hi friends
    I want to know how to run a batch file as windows NT service.
    I got some information in the following link
    http://support.microsoft.com/kb/q243486/
    I tried it but i want to know what we need to include in Autoexnt.bat
    And one thing i need Instexnt.exe file. I cannot find tht file.
    Please search tht file and send me tht file or else send the link in which this file is present
    Please give me reply fast.its very urgent.
    Thanks in advance.

    Hi,
    My aim is to run a MS-DOS Batch file, that I created to run a Java Prgram.
    I need to call the Batch File from the Oracle Procedure, Also I may need to change the content of the Batch File (Argument to the Java JAR File ).
    I can keep the JAR FIle either in the Oracle Server or in the Application Server.
    The Java program is to convert XML Format FIle to PDF and MS Word format.
    Oracle Version : 10g 2.0.1.0.
    Thanks in advance
    Rizly

  • How to run a batch file

    Hi,
    How to run a batch file from Oracle. Is it possible directly from PLSQl, or should I write the java code.
    Oracle Version: 10g 2.0.1.0.
    Thanks in advance
    Rizly

    Hi,
    My aim is to run a MS-DOS Batch file, that I created to run a Java Prgram.
    I need to call the Batch File from the Oracle Procedure, Also I may need to change the content of the Batch File (Argument to the Java JAR File ).
    I can keep the JAR FIle either in the Oracle Server or in the Application Server.
    The Java program is to convert XML Format FIle to PDF and MS Word format.
    Oracle Version : 10g 2.0.1.0.
    Thanks in advance
    Rizly

  • How to read some files inside the jar

    Hi,
    I have an applet that runs with JWS. The user can input some information and then I need to show this information in a web page. As the application can be run offline, I cannnot use JSP�s to generate the web page. The information is saved in a xml file, so I use a xsl parser to generate the html code. The problem is that I have to include some javascript files (.js). I put these files inside the jar, but, how can I read these files, or how can I reference these files from inside the html page ?
    Thanks !

    You can use getClass().getResource(classpath)
    to get a stream version of the data from your
    jar file. If you need to put it in a file, you
    can write that stream to a file in a temp directory.
    classpath is the classpath of your js file

  • Running a batch file - VERY URGENT .. help

    Hi people
    I am attempting to run a batch file from with a JSP page.
    the code i am using is:
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec("cmd.exe /c d:\\uploadfiles.bat");
    This jsp file is located on the c: of a webserver.
    the uploadfiles.bat is located on the d: of the webserver and the code is:
    copy d:\videos\008214?.rm d:\blah
    copy d:\images\008214.* d:\blah
    copy d:\xml\008214.* d:\blah
    cd \blah
    pkzip -es -m 008214.zip *.*
    copy 008214.zip d:\upload\008214.zip
    del 008214.zip
    If I run this batch file from a command line, it works fine, though when I try and call it through my JSP page, it doesnt do anything .. a command window just pops up for a while, and then closes.
    How can I fix this ... I need this quite quickly
    Thanks people

    1) It is O.K. that you see nothing in that console. Its output is captured by Java and is not displayed on the screen.
    In general, that console should not be visible, but actually it behaves differently according to JDK and OS versions (treat that as a feature).
    2). Look at this article:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    It it does not answer your problem, try to search the forums:
    http://search.java.sun.com/search/java/index.jsp?qp=%2Bforum%3A31&nh=10&qt=%2B%22exec%22+-%22Replies%3A+0%22&col=javaforums
    Questions about Runtime.exec() has been asked hundreds of times.
    3) runtime.exec() can execute BAT files. It is not necessary to specify that "cmd /C".

  • Problems Force Running a batch file

    Hi There,
    I am trying to force-run a batch file to copy files from a local NBO Appliance to the C:\tmp directory on the user's workstation. The batch file lives at c:\tmp\branding.bat.
    I cant get the batch file to force run. Zen reporting advises that the batch file has distributed and launched successfully, however the files do not copy.
    However, if i click on the icon for the batch file app - the files copy no problem. I have tried running Workstation Associated and (Unrestricted) User Associated as well as Workstation - Force Run as User.
    Path to executable file:
    %*WinSysDir%\cmd.exe
    Parameters:
    /c "c:\tmp\branding.bat"
    Any ideas? The batch file has to refer to the P: drive as the application covers 40 different sites each with their own appliance containing source files.
    Running NBO2 - ZFD 4 Agent 4.0.1.60 - Clientless
    Desktop XP Workstations
    Thanks
    Thax

    Have the app object copy the batch file to the hard drive from the
    server and then run it locally. This should work with a Middle Tier server.
    thax wrote:
    > Hi there,
    >
    > I cant use the actual server name as this is an application which runs
    > through a middle tier server for multiple NBO sites so therefore needs to
    > use the P: reference...
    >
    >>>> kokoo<[email protected]> 9/03/2006 12:37 >>>
    >
    > TRY edit Scrirts:
    > #\\FS_SERVER_name\VOL\BATCH.BAT
    >
    > edit batch file:
    > xcopy "p:\nal\wxp\ZenPolicies\Branding\*.*" "C:\tmp\ZenPolicies\Branding\"
    > /s /v /e /y
    > ==>
    > xcopy p:\nal\wxp\ZenPolicies\Branding\*.* C:\tmp\ZenPolicies\Branding\ /s
    > /v /e /y
    >
    > "thax" <[email protected]>
    > *******:[email protected]...
    > Hi Jeremy,
    >
    > xcopy "p:\nal\wxp\ZenPolicies\Branding\*.*" "C:\tmp\ZenPolicies\Branding\"
    > /s /v /e /y
    > pause
    >
    > Thax
    >
    > >>> Jeremy Mlazovsky<[email protected]> 8/12/2005 00:20
    >
    > Can we see the contents of your batch file?
    >
    > thax wrote:
    > > Hi There,
    > >
    > > I am trying to force-run a batch file to copy files from a local NBO
    > > Appliance to the C:\tmp directory on the user's workstation. The batch
    >
    > > file lives at c:\tmp\branding.bat.
    > >
    > > I cant get the batch file to force run. Zen reporting advises that the
    >
    > > batch file has distributed and launched successfully, however the files
    >
    > > do not copy.
    > >
    > > However, if i click on the icon for the batch file app - the files copy
    >
    > > no problem. I have tried running Workstation Associated and
    > > (Unrestricted) User Associated as well as Workstation - Force Run as
    > User.
    > >
    > >
    > > Path to executable file:
    > >
    > > %*WinSysDir%\cmd.exe
    > >
    > > Parameters:
    > >
    > > /c "c:\tmp\branding.bat"
    > >
    > > Any ideas? The batch file has to refer to the P: drive as the
    > > application covers 40 different sites each with their own appliance
    > > containing source files.
    > >
    > > Running NBO2 - ZFD 4 Agent 4.0.1.60 - Clientless
    > >
    > > Desktop XP Workstations
    > >
    > > Thanks
    > >
    > > Thax
    > >
    >
    >
    Jeremy Mlazovsky
    Senior System Engineer - Enterprise Desktop
    UDit-Central Hardware Systems & Network Storage
    University of Dayton
    http://forge.novell.com/modules/xfmod/project/?udimage
    http://vmpconfig.sourceforge.net/
    http://regeditpe.sourceforge.net

  • Running a batch file in a java servlets programme

    this is what i have
    Process p = Runtime.getRuntime().exec("C:\\sync.bat");
    Now i need a way for the program to wait until this is finished running. I dont want to print anything until this is done. Is there a way to do this

    Will this even run sync.bat or do i have to do more.Here is my entire code
    import java.io.*;
    import java.io.File;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.swing.*;
    public class index_test extends HttpServlet
         public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
              res.setContentType("text/html");
              PrintWriter out = res.getWriter();
              out.println("<HTML>");
              out.println("<body>");
              try
                   Process p = Runtime.getRuntime().exec("C:\\sync.bat");
                   String dir = "C:\\Perforce";
                   File what = new File(dir);
                   String [] listy = new String [100];
                   String [] products = new String[5];
                   String lists;
                   listy = what.list();
                   out.println("<form action =getBuilds Method = get>");
                   out.println("Please select which Product you wish to search in: ");
                   out.println("<br>");
                   int j = 0;
                   if(listy[j] != null)
                        products[j] = listy[j];
                        j++;
                   int i =0;
                   for(i = 0; i<listy.length && listy[i] !=null;i++)
                        out.println("<input type ='radio' name = 'product' value='"+dir+"\\"+products[i]+"\\build'>");
                        out.println(products);               
                        out.println("<br>");
                   out.println("<input type ='submit' value ='Submit'>");
                   out.println("<br>");
              catch(IOException e){}
              out.println("<img src='C:\\tomcat4\\webapps\\Tracker\\dancing2.gif'>");
              out.println("</form></body></html>");
    What i need is to run sync.bat, wait till its finished then print out the folders in the Perforce directory. I can print out the contents of Perforce grand i just dont know how to run the batch file and get the progeam to wwait until its finished

  • Running a batch file

    String path = "";
    path = "cmd /c start FCall.bat";
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(path);
    //proc.destroy() ; The code works fine, however, I need some help in exiting the command window. After executing the batch file the window should close. I have tried "destroy" didnt work it kills the entire process. Is there a function I am missing to accomplish this ?

    warnerja,
    I am compiling my program through command prompt. One of my method that contains the above mentioned code, runs the batch file. In doing so, it opens cmd.exe window. I want that window to be closed once the batch file ends running.
    The path associated with the cmd.exe is the same as the path where I am compiling my java code.
    Any suggestion ?

  • Running a batch file on ftp server

    HI All,
    i am trying to use Command line facility of file adapter to run a batch file..
    i batch file i have a single command as
    mkdir ranjeet.
    how should i call this batch file from file adapter..
    i tried putting batch file name in the command line section. I had copied the batch file on ftp server at location of Target Directory..but in audit log of adapter i am getting error as OS command cannot be executed..

    Ranjeet,
    >>ok..but what will command to be run of ftp run..
    How do you expect any one of us to know what your ftp server is based on.
    The previous reply by Carme has answered your XI query and to the point. You acknowledge it with a <b>ok</b>!! I guess it is too rude on your part.
    Anway answering your question, that depends on your FTP server. Log in to your FTP server manally and try executing these commands and check.
    Regards,
    Jai Shankar

  • Running a batch file placed on a remote terminal????

    Hi all,
    How can I run a batch file which is located in machine A from machine B.?
    which is the best technology to go for?
    In RMI I need to have a server program running always to run the batch file, so any other alternative where in on demand invocation of batch file can be done.
    A web service is going to invoke this, so plz give me the best way to do this guys..
    waiting for ur reply
    Mithun

    How can I run a batch file which is located in
    machine A from machine B.?
    which is the best technology to go for?JVirus

  • Running a batch file on  a web server

    hi,
    i am facing a problem regarding running a batch file(with a java command in that file) on a web server.
    i am having a batch file which is running a chatapplication (this file is having a single line -- "java ChatServer 8080")
    i want to execute this command ( file ) on my web server
    can u help me plz ( i think u can)
    thanx 4 reading my problem...
    -ashish

    thanx 4 replying
    but as i am a developer and i am developing the aplication for a client, so should i speak to the client for this or can i do this without interrupting them?
    -ashish

  • Running a batch file in Java. Urgent!!

    I want to run a batch file present at a particular location in Java.Although I am running two codes suggested by many people, i am still not able to run the batch file. My codes run as below :-
    CODE 1
    Process P;
    Runtime rt = Runtime.getRuntime();
    P = rt.exec("C:\\test.bat");
    CODE 2
    Process P;
    Runtime rt = Runtime.getRuntime();
    P = rt.exec("C:\\WINNT\\System32\\cmd.exe C:\\test.bat");
    I have tried both these codes but without success. But I have observed that in the Task Manager, whenever i run the above codes in a servlet, a "CMD.EXE" is being created in the "Processes" Bar each time but the batch file neither opens up nor it runs.
    Please suggest me some method to run this batch file in Java.
    Or if u can suggest the reason behind the above observation and any corrections i can make to run the batch file. Thanks in advance.
    Ankit

    i want to get more than one command prompt while running the program
    am giving the problem
    import java.io.*;
    class CmdDemo
         CmdDemo(String ls) {
              try
              Process p;
              Runtime rt=Runtime.getRuntime();
              p=rt.exec(ls);
              catch(IOException ioe)
                   System.out.println(ioe);
         void showcmd(){
    new CmdDemo("cmd");
         public static void main(String args[])
              new CmdDemo("cmd");
              new CmdDemo("C:/WINDOWS/System32/cmd.exe");
              new CmdDemo("cmd");
              new CmdDemo("regedit");
              new CmdDemo("regedit");
              new CmdDemo("notepad");
              new CmdDemo("notepad");
              //CmdDemo cd=new CmdDemo("cmd");
              //cd.showcmd();
    here am getting two notepads ,two registry editors
    but only one command window
    i would be very greateful if u could help me
    plz reply to my id [email protected] too

Maybe you are looking for

  • Why can't I resize a text box in the new Preview in Yosemite?

    I just upgraded to Yosemite, and I am having trouble with the new Preview.  I am a student and my notes are pdfs.  I have been using Preview to take notes on the pdfs for the past two years.  I have always been able to insert a text box, make it a ce

  • New gl with open item

    Hi experts, out user by mistakely created one gl account with out open item management and posted to the gl account, but not they want to put open item tick mark, if i create new gl account with open item and how can i transfer the posted items to th

  • Adding new fields in CAA1/2/3 through BDT

    Hi, My reqirement is to add some custom fields on the contract account screen ( CAA1/2/3 ). I am new to BDT... please help me out Edited by: abapdevelopersap on Nov 1, 2010 9:07 AM Moderator Message: Please search for available information before pso

  • Starter album 3.0

    How do I export photos from the album say to email or to a cd. Do I need to upgrade to a higher version. Thanks. Bob G.

  • XMLTYPE Transform works differently in Oracle 10.1 and 11.2

    We are migrating our applications from Oracle 10.1g to 11.2g. We have a number of PL/SQL routines that transform incoming/outgoing XML using the XMLType Transform method. The XSLTs that we use do not seem to work in 11.2. For example, the code below