Runnig DOS commands from the java code?

Hi reader,
how can I execute DOS commands (I am on an Windows XP Machine) from my java code and also capture the output?
I think the
runtime.exec(command)
only executes win32 processes.
Please suggest
TIA
Ayusman

Again, this link should tell you most of what you need to know:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
You're not limited to the Win32 platform unless you're using specific DOS commands. Perhaps if you're just after file system information then some of the classes in the java.io package can help.
If it's not enough, perhaps a resource bundle or something similar can provide you with the names of the external programs you need to run, i.e. "dir" for win and "ls" for *nix.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How to register a dll from the java code

    Hi,
    We can use windows utility Regsv32.exe to register a the components. Is it possible to register the Dll from the java code. If possible please try to provide me the code for the registring the dll.
    Thanks in adavance
    Aswad

    if a try this variant it doesnt work
    static {
            System.loadLibrary("shellExec.dll");
    but in this way it work (without .dll extension)
    static {
            System.loadLibrary("shellExec");
    }

  • Can we execute DOS Commands from a Java Application

    I just want to know whether we can execute DOS Commands from a Java Application.
    Thanks.

    hi,
    try this:
    Runtime.getRuntime().exec("cmd /c start abc.bat");
    andi

  • Test.jsp not able to display the output from the java code.

    when i try to invoke http://localhost/papz/test.jsp
    I dont see anything. The page is blank. And there are no error messages in any log files. When i click on view source in IE i get to see the entire source code, including the jave code.
    <html>
    <head>
    <title>Test</title>
    <body>
    <%
    out.println("Hello World");
    %>
    asdfasdfasdf
    </body>
    </html>
    i added in the asdfasdf to see whehter it will be printed or not... It does print that stuff out.
    when i try to invoke the login.jsp page, i get the dialog box "save this file to disk"
    Any clues whats going on...?
    I followed the instructions...over and over again... but it doesnt seem to help.
    win nt 4.0
    apache 1.3.12
    jserv 1.1.1
    Pls help. Thanks

    Hi,
    Have you solved your problem?
    I4m trying to do the same, but I installed portal 30, then portal to go, and when I try to run test.jsp I get the following error:
    Request URI:/papz/test.jsp
    Exception:
    java.lang.NoSuchMethodError: oracle.jsp.util.JspUtil: method
    stripTarget(Ljava/lang/String;C)Ljava/lang/String; not found
    Thanks
    Pablo Lopera
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by NewBie:
    when i try to invoke http://localhost/papz/test.jsp
    I dont see anything. The page is blank. And there are no error messages in any log files. When i click on view source in IE i get to see the entire source code, including the jave code.
    <html>
    <head>
    <title>Test</title>
    <body>
    <%
    out.println("Hello World");
    %>
    asdfasdfasdf
    </body>
    </html>
    i added in the asdfasdf to see whehter it will be printed or not... It does print that stuff out.
    when i try to invoke the login.jsp page, i get the dialog box "save this file to disk"
    Any clues whats going on...?
    I followed the instructions...over and over again... but it doesnt seem to help.
    win nt 4.0
    apache 1.3.12
    jserv 1.1.1
    Pls help. Thanks<HR></BLOCKQUOTE>
    null

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • Running a dos command from a java application

    hello,
    I'm trying to execute a batch file from a java application. I tried with:
    try
    Process proc=Runtime.getRuntime().exec("fop -fo "+iXmlFoFile+" -
    svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                               the Xml FO file into Svg file: "+e);}
    and with:
    try
    Process proc=Runtime.getRuntime().exec("cmd ./c fop
    -fo "+iXmlFoFile+" -svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                the Xml FO file into Svg file: "+e);}
    but i have a IOException: CreateProcess: .... error=2
    When I try these line to launch a .exe file it works but not with a .bat file.
    I also tried:
    String execstr = "fop -fo "+iXmlFoFile+" -svg "+SvgFileName;
    String [] commandArray = { execstr };
    try {
    Runtime.getRuntime().exec(commandArray);
    } // end try
    catch ( Exception e ) {
    System.out.println( e.getMessage() );
    e.printStackTrace();
    }// end catch
    but i got the same exception in java.lang.Win32Process.create
    What did i do wrong?

    Your execution string is a bit more that I want to figure out, but here are a couple ideas:
    Is the working directory of any importance? If so you'll need to set that when you do your exec()
    I think I remember reading something about batch files that couldn't be kicked off via this method. Perhaps you need to execute the string "start mybatchfile.bat". Seems like you need to do something like that to get a command interpreter to run your batch file.

  • Executing jar command from the java application

    Hi All,
    In my application i want to create a jar file with the existing class @ Runtime and want to download . But i tried to execute the jar command via Process.getRuntime, it throws IOException. Please guide me or give the solution

    PavithraKarthikeyan wrote:
    Please guide me or give the solutionQuestion your need for this. Why do you think you need to create the jar file.
    P.S. The jar command is only available if the user has the JDK installed so if he has only the JRE installed then you have a problem using Runtime.exec(). There are classes (java.util.jar.JarFile et al) that will allow you to jar files using Java code.

  • Can we set a variable used inside the template from the java code.

    Hi everybody,
    I am uploading template,sub template and data xml fle to generate the preview using XDO API's. My main template is calling a sub template so it needs to import the sub template in the main template.since i am uploading my files on a particular server,my subtemplates has been put on different path as specified in the main template.
    so i need to change the subtemplate path dynamically at run time.
    is there any way i can pass this information to my main template at run time.
    one solution could be,my rtf template has a variable 'i' inside it,which is setting the file path to include my subtemplate like this :
    <?xdoxslt:set_variable($_XDOCTX, i ,"import:file:///c:/Temp/htmlmarkup.xsl")?>
    <?xdoxslt:get_variable($_XDOCTX, i )?>
    now is there any way i can set this variable at run time from my external java code.?
    Thanks,
    Anuradha

    Thanks for the response.
    but i still am looking for the solution.
    if both my template and subtemplate are in the same directory then atleast
    <?import:file:../htmlmarkup.xsl?> should work.
    but its not working...i m getting following error:
    FOProcessor setData: C:\subtemplates\projects.xml
    FOProcessor setLocale: en-us
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLT10gR1.invokeNewXSLStylesheet(XSLT10gR1.java:514)
         at oracle.apps.xdo.common.xml.XSLT10gR1.transform(XSLT10gR1.java:192)
         at oracle.apps.xdo.common.xml.XSLTWrapper.transform(XSLTWrapper.java:156)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:916)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:869)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:204)
         at oracle.apps.xdo.template.FOProcessor.createFO(FOProcessor.java:1535)
         at oracle.apps.xdo.template.FOProcessor.generate(FOProcessor.java:925)
         at RTF2PDF.runRTFto(RTF2PDF.java:590)
         at RTF2PDF.runXDO(RTF2PDF.java:443)
         at RTF2PDF.main(RTF2PDF.java:237)
    Caused by: java.io.FileNotFoundException: C:\Documents and Settings\fusion\htmlmarkup.xsl (The system cannot find the file specified)
         at oracle.xdo.parser.v2.XSLProcessor.reportException(XSLProcessor.java:782)
         at oracle.xdo.parser.v2.XSLProcessor.newXSLStylesheet(XSLProcessor.java:564)
         ... 15 more
    please suggest me what to do..

  • Executing DOS command from within java.

    I have an XML file and an XSLT stylesheet.
    I want to process this XML file using XSLT stylesheet from java. Using saxon.
    Here is the java class I wrote --
    class DOSCommand {
    public void exec_command(String[] cmd) {
    try {
    Process child = Runtime.getRuntime().exec(cmd);
    } catch (IOException e){
    System.out.println("Error");
    System.out.println(e.getMessage());
    finally{
    System.out.println("Finally");
    In my servlet class I am instantiating the DOSCommand object and calling the method
    DOSCommand d = new DOSCommand();
    String[] c = {  "c:\\Program Files\\saxon\\saxon.exe", "-o",
    "PO.html", "ePO.xml", "POE.xsl"
    d.exec_command(c);
    But I am not getting results. It does not give any error. But does not process the XML file and the Date/timestamp of PO.html does not change.
    I know that Definition/Creation of DOSCommand object is not necesssary here. But we can disregard it.
    Please let me know where I am going wrong !
    Avinash.

    Probably where you are going wrong is in failing to specify your working directory, so your command can't find "PO.html" and so on in the default working directory for that command. But that's not really the answer. The answer is not to do it in that way in the first place. Saxon has a Java API and its documentation has a section entitled "Embedding Saxon in an application".

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • Do quires from my java code

    i am supposed to work on a project that dos query from my java code on one of the web medical sites,but I dont how to start on this ,if any one could help me with an exmple or link??

    hi,
    thank you for responding on my email , I went to the website you recommended ,but it gave me list of projects ,I dont know what to choose , please be advised I am just A biggennner and I have to do ap roject, that uses any language either java or c++ to do an automatic search from a certain website and retrieve the recordes to process ,
    I dont know which easier to work with c++ or java ,and how to do theat qurey search,
    i will be more than grateful if you advice and perhaps lead me to an example on this
    all the best.

  • Query using the SQL 'go' command  on a JAVA code

    Hi,
    I am trying to create a new database on MS SQL and at the same time verify whether the data base exist already and then add a new table. The query statement works well on the query windows on MS SQL, but when the query is place using a JAVA code it gives the following error:
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'go'.
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'go'.
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
         at DataBaseCreator.main(DataBaseCreator.java:30)
    I have to add that if I only query: "CREATE DATABASE NameOfDatabase" the new data base is created without a problem using JAVA, but when I try to use the following query, I got the error message.
    "USE Master "
                        + "IF EXISTS (SELECT * FROM SysDatabases WHERE NAME='DatesTemps') "
                        + " DROP DATABASE DatesTemps"
                        + " go "
                        + " CREATE DATABASE DatesTemps22 "
                        + " go"
                        + " USE DatesTemps "
                        + " CREATE TABLE Fable ( "
                        + " FableID INT NOT NULL CONSTRAINT FablePK PRIMARY KEY NONCLUSTERED, "
                        + " Title VARCHAR(50) NOT NULL, "
                        + " Moral VARCHAR(100) NOT NULL, "
                        + " FableText VARCHAR(1536) NOT NULL, "
                        + " BlobType CHAR(3) NULL DEFAULT 'doc', "
                        + " Blob IMAGE NULL DEFAULT NULL )"
    If it is useful my complete code is the following, I appreciate in advance your comments.
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    public class DataBaseCreator {
         public static void main (String[] args)
              Connection Time =null;
              Statement stmt = null;
              String data = "jdbc:odbc:DataBaseCreation";
              try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Time= DriverManager.getConnection(data,"","");
                   stmt = Time.createStatement();
                   //String query;
                   //java.sql.Timestamp ts1 = new java.sql.Timestamp(((3*60)+58)*60*1000);
              // System.out.println(ts1 + " This is a Time Stamp");
              ResultSet rec = stmt.executeQuery(
                        "USE Master "
                        + "IF EXISTS (SELECT * FROM SysDatabases WHERE NAME='DatesTemps') "
                        + " DROP DATABASE DatesTemps"
                        + " go "
                        + " CREATE DATABASE DatesTemps22 "
                        + " go"
                        + " USE DatesTemps "
                        + " CREATE TABLE Fable ( "
                        + " FableID INT NOT NULL CONSTRAINT FablePK PRIMARY KEY NONCLUSTERED, "
                        + " Title VARCHAR(50) NOT NULL, "
                        + " Moral VARCHAR(100) NOT NULL, "
                        + " FableText VARCHAR(1536) NOT NULL, "
                        + " BlobType CHAR(3) NULL DEFAULT 'doc', "
                        + " Blob IMAGE NULL DEFAULT NULL )"
              catch( Exception e )
                        System.err.println( e );
                        e.printStackTrace();
              finally
                        try
                             stmt.close();
                             Time.close();
              catch( Exception e )
                        System.err.println( e );
    }

    Ok, first of all thanks for your answer, now what I want to do is the following:
    1) I need to input ((retrieve) every minute some data (Date and Temperature), that I will get from and external device, this is not part of this code.
    2) I want to store that data (Date and Temp) on a data base, here where I need the command to create the data base and to verify whether that data base already exists. In case it has already been created then create new table(s) on it. If it doesn't exist then create and then create new tables.
    3) Each Day (at yyyy mm dd 00:00:00:000 will create a new table, and the name of this table will be yyyymmdd.
    4) Then every minute the java code will retrieve the data and add it to the table in the data base.
    5) That will be a close loop that will be running until the user interrupt it.
    I haven't make the communication code yet, in order to test my code I was thinking to retrieve the data from another data base. This would be just to verify that the JAVA sequence is able to retrieve the data every minute and create new data base and tables.
    For the record I am able to send the queries and retrieve information from SQL running the code in eclipse, that will cover your first observation.
    I am quite new in the forum I am sorry I didn't get the use of code tags.
    Sorry again as I said I am quite new on this, what's a DDL statement.
    Thanks.

  • Executing a dos command from java in windows nt

    i need to execute the
    " net send"
    command from the command line in windows nt, from within my java program... is there any way that i can execute cmommands in the dos command shell? or rather, does anybody know a way i can send a message ( in windows ) from java, from one computer to another over the lan?? I cannot have a java programming running on all the other computers, so i cannot make my program serve, it must just send the messges using a lan command....
    (the net send command just sends a message in the form of a pop up box on the receiver's screeen)
    thanks a bunch guys!!!
    Thanks a bunch guys!!!!

    you can do that with exec() in Runtime.
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(command here);but before you do that you need to read this:
    http://www.javaworld.com/jw-12-2000/jw-1229-traps.html
    hth
    partha

  • DOS command from java applet

    Hi, I need to perform a DOS command from Java (using WFC if needed)...
    I have no idea, so please help!
    Thank you.

    OH OH OH WAIT! It is an Applet! i think there will be some security issues here! Sure enough you can't execute commands on the system from an applet unless you make some changes on the java.policy files on the client machine (that means, if your applet is in a web page, every machine which view your page).

  • I need to set a proxy to visite internet, when i invoke the firefox 3.6 from my Java code, my setting would be disappeared. So i wonder whether the fire fox has the start up parameter to control this, thanks!

    1: I need to set aproxy in firefox 3.6, which allow me to access the internet.
    2: Currently i am using some Java code to invoke the firefox, the path is D:\Program Files\Mozilla Firefox\firefox.exe. When the firefox launched by Java code, I found the proxy is missing.
    3: looks like the Java code make the firefox go back to the orininal status, just like the fresh installation.
    I wonder whether there are some parameters or files that can be used to control the firfox starting.

    Thanks for your reply, here is what i tested:
    1: Upgrade my Firefox version to 3.6.8
    2: The installation path is D:\Program Files\Mozilla Firefox\firefox.exe
    3: For the ProfileManager, I tried to run the firefox.exe -ProfileManager in command line, the firefox was started up but not the profileManager. No sure why this happened. :-(
    4: I updated some features after the installation, like add some bookmarks, delete some default bookmarks and added the proxy. When the firefox is started from my code, the profile would be the default one(No new bookmarks, no proxy).
    5: Start the firefox from the command line and by double click is ok, my adding bookmarks and proxy is here...
    Thanks!

Maybe you are looking for

  • Credit Management not working for Third Party Sale

    Hi Experts, We have a scenario of Third party sale where sales order generate purchase requision after saving. Now we have appled static credit check to the customer, at the time of saving sales document it warns credit limit is over same time it doe

  • How to make the obligate field in selection screen

    Hi , In my report two radio buttons and two bloc selection screens are there.When we select the first radio button first screen will be editable second screen will be non-editable vice-versa. but the problem is in each selection screen one mandatory

  • After resetting my IPad to factory settings, how can I reset to my most recent ICloud backup?

    I have reset to factory setting on my IPad and would like to restore to my most recent backup setting on ICloud. How can I do this?  Do i need to delete everything before I see the Setup Assistant option?

  • File reader validation

    hello everybody i have a file reader which is successfully reading from a .txt file but i need to validate it also,if the begining of each line is a particular key then i need to control my display rather than displaying the whole text as it is .. th

  • Ipad 1 AV adaptor won't work

    I bought a HDMI AV connector for my Ipad 1 and i can't get any video on screen - My new Ipad works fine. Any ideas. Thanks Mike