Run a dos ommand using java

Hi,
I want to execute a dos command using java but i am geting some runtime execption.
I code i wrote:
================
import java.io.*;
import java.util.*;
public class docCom {
public static Runtime run1 = Runtime.getRuntime();
public static void main(String args[])
try{
BufferedReader in = null;
//Runtime r = Runtime.getRuntime();
String [] commands = {"ftp adas.co.in", "aaaaa", "zzzzz", "cd demo", "hash", "mget aaa.txt"};
Process p = Runtime.getRuntime().exec(commands);
String line = new String();
if (p == null ) {
System.out.println("Could not connect");
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = in.readLine()) != null ) {
System.out.println (line);
catch (IOException io){
System.err.println(io.toString() + "*******" +io);
The purpose of the code it to
1) ftp server adas.co.in
2) provide login and password info
3) then mget a file from server to the local machine.
Error i am geting
java.io.IOException: CreateProcess: "ftp adas.co.in" aaaaa zzzzz "cd demo" hash"mget aaa.txt" error=2*******java.io.IOException: CreateProcess: "ftp adas.co.in" aaaaa zzzzz "cd demo" hash "mget aaa.txt" error=2
Press any key to continue...

Cross Post:
http://forum.java.sun.com/thread.jspa?threadID=780815&messageID=4441376#4441376

Similar Messages

  • Running Oracle forms 9i using java plug in 1.4.x

    Hi,
    i want run my forms (9i) using java plug in 1.4.x? could u plz tel me what are changes i have to do in formsconfig and in other places.

    Thanks for the reply.
    I am using Webutil 1.06 an jacob 1.8 with Oracle forms 9iDS (9.0.2.9 version)
    i have gone through, step by step as u said,
    but form is not running.. i am able to run the form using java-plug-in (1.4.2.)
    but when i am implenting with webutil, form is not running...
    as i studied the links given by u, in that webutil is compatible with only from 10g.
    if so, which is the compatible webutil version for Oracle forms 9iDS (9.0.2.9 version).
    My actual goal is to store a file (it may be .doc, .pdf, .xls, .ppt) in the database and retrieving through forms..
    and also suggest me if there is any other ways to do it..
    plz suggest me..
    Naresh.P

  • Running Dos Command using Java

    How do i run a particular Dos command using a simple java class?

    Process process = Runtime.getRuntime().exec( ... );
    Search the forum. There are plenty of examples.

  • How can I run a dos command from java on windows 98, 95?

    The usage of cmd.exe in the java program to run a dos command on windows 98. 95 doesn't work as the equivalent command is command.exe
    But using the command.exe in the java program makes my program to hang.

    hi,
    As u mentioned, u cannot use the cmd.exe in win9x environment as cmd.exe is specific to windows NT, you can use the command.exe without any hitches.
    for eg
    java.lang.Runtime.getRuntime().exec("start command /K a.bat"); should run the batch file a.bat..
    if the problem persists, try posting the snippet of code that you are using.
    cheerz
    ynkrish

  • Run An OS Command Using Java?

    I want to write a java class that does some Unix system maintenance. In particular, I want to read some data out of a database and then do some calculations to figure out which files in particular can be tarred and zipped. The database part is already handled (in other words, I can identify the files I want to take action on) but I'm not sure how to run an operating system command (e.g. "tar cvzf myfile file1 file2 file3") using java.

    Read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    %

  • How to run a jar file using Java application.

    Hi all,
    I know that jar file can run using the following command, using the command prompt.
    java -jar jar-fileBut I don't know how to run that command through a Java code. Hope it's clear to you.
    So can you please explain how can I do it.
    Thanks,
    itsjava

    rayon.m wrote:
    The solution given by ropp appears to have nothing to do with what you asked about.Ok sir, I got the point.
    I've try a test as follows. But it doesn't give any output. Even not an exception.
            try {
                String[] temp = new String[]{"java", " -jar", " MainApp.jar"};
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(temp);
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);
                System.out.println("Temp_Values");
            catch(InterruptedException ex) {
                System.out.println(ex.getMessage());
            catch (IOException ex) {
                System.out.println(ex.getMessage());
            }I've debug and see, but the exitValue is even not exist at run time. Can you tell me where I'm going wrong.

  • Running MS-DOS commands using Runtime.exec()

    Is there any way to run the dos commands like copy and del from our java program? Actually I want to implement a visual console kind of thing and have to transfer the commands to the prompt and get the result string that is to be displayed in a JTextArea?
    Please help me. It'll be very nice of you...thanks

    I can help you in two ways:
    o by telling you to run cmd.exe and pass the rest as parameters.
    o by pointing out this is the wrong forum for you equestion.

  • Running a Batch file Using Java

    hi All ,
    I am executing a DOS batch file using the Java .
    I am using it as
    Process P;
    Runtime rt = Runtime.getRuntime();
    P = rt.exec("C:\\X12TST\\BATCH1.BAT ");
    But in case BATCH1.bat have call to some other Batch File Say Bactch2.bat , i am not getting the output of BATCH2.BAT .
    My Java Program exits as soon as it enters to the point where BATCH1 is calling BATCH2 using (call BATCH2.bat).
    Any help is resolving the problem is highlt appreciated .
    Please advise me if you have any alternative to solve the problem .
    Thanx in advace

    The Runtime.exec() should'nt be used with a .bat or .cmd file since .bat and .cmd are not really executable. I think the expected behaviour you experimentred is a process hang at the last command line of the .bat file.
    Insert "echo XXX" or "net send mycomputer XXX" debug messages in your .bat, you'll see the .bat executes until last line. But the last one NEVER terminates, resulting in a hang in the Java thread doing a process.waitFor().
    The only workaround (or right use of exec) is to call the cmd.exe (with FULL PATH OF cmd.exe SPECIFIED in the exec() call). An exec() calling C:\WINNT\System32\cmd.exe /C mybatch.bat should return properly, cause cmd.exe is a standard Win32 program that will be launched to interpret mybatch.bat then terminate.
    PLEASE UNIX/LINUX USERS : report if the behaviour you get is the same on your plat-form, or if it is -one more- bug in win32 OS. Can you exec() a shell script direcly or do you have to exec() a "bash" or "ksh" or "csh" with you shell script as command line argument ?

  • Inovoking a MS-Dos application using java

    hi
    I have .exe application which takes a parameter(name of a text file). I would like to know if I could write a java program to invoke the appliation take the input parameter and run the MS-dos application and how can it be done in java.
    thanks in advance
    jaggi

    [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html]java.lang.Runtime.[url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String)]exec( ... ).

  • How to run a batch file using java

    Hi guys,
    I want to run a batch file by running a java program.
    i have tried for this code, but it is not working , plz guide me code.
    Runtime r = Runtime.getRuntime();
         Process p = null;
         try
              String[] cmd ={"cmd","/c","C:\\jarkarta-tomcat-3.2.3\\webapps\\DDS\\Resumes\\leap.bat"};
              p = r.exec(cmd);
         catch(Exception e)
         System.out.println("Exception in Runtime batch processing."+e);
         }

    You will need this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Check if a service is running on remote IP using java

    Hi all,
    hope I'm posting to the right section of the forum anyway I was wondering if anybody would have an idea how I could go about doing the following:
    I have added a dialog to our application, when i hit the Launch button is opens up a web browser with a url that gets passed in the code.
    The url is the ip address followed by : followed by port number. The web page then displays that web page with login screen for the application running on that IP address.
    Before I pass the url above to the code that opens the web page I want to be able to check that a service is running at the IP address and if it's not I dont want to open the web browser with the passed url. The reason I need to do this is that if the service has been unstalled from that IP I dont want to open a web browser.
    Would anybody know how I could check if that service is running on that IP address remotely?
    Thanks for your help in advance,
    Valerie

    The only way to determine if a remote service is not running is by waiting for an exception to occur when you're trying to connect to it. You could make your service so that it supports an is-alive request of some sort.

  • Long running reports using java servlets

    Hello,
    I'm running into a problem using java servlets to produce database reports and sending them back to the client browser as excel or html. The problem comes into play when the user has submitted two reports then goes to run a third and the browser hangs. I realized now that this is because of the two active connections that the user already has to the app server. Does anyone have any suggestions on how to get around this? I'm trying to now write the report to the server, and provide the browser with a url, but it seams as though the connection isn't totally closed even though I close the response printwriter.... Any suggestions would be greatly appreciated....

    Unfortunately I dont have an answer to your question, but:
    If the reports are large/long running, should they be generated on demand? You could schedule the reports to be generated every day, month or whenever appropriate, stored on the server and then quickly pulled by the user whenever needed.

  • Running unix command using java shows error

    Hi All,
    I am trying to run UNIX move command using Java exec method but its throwing error, unable to rename. Here below is the code i am trying to run to move all files from one directory to another directory. source and destination directory exists.
    public class Demo
        public static void main(String args[])
            try
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("mv /home/demo1/* /home/demo2");
                int exitVal = proc.waitFor();
                System.out.println("Process exitValue: " + exitVal);
            } catch (Throwable t)
                t.printStackTrace();
    }if i give "mv /home/demo1 /home/demo2" in exec method, its working, with * character its giving problem.
    Please help me in resolving the problem.
    Thank you

    Characters like *, >, &, |, etc. are interpreted by the command shell--that is by the bash, zsh, etc. programs. When you execute a command with ProcessBuilder or Runtime.exec, you're not going through one of those shells, so their interpretation of those characters is not available.
    In your code, the character * is being delivered directly to the mv command (which doesn't think * is anything special), as opposed to being turned into a list of files and directories as it would be when it's interpreted by the shell. The mv command doesn't know anything about the * character being special.
    If you want to have those shell interpretations, you need to execute the command through a shell. One example is like so, but a) you'll want to read up on the methods in exec() that take arrays of String, and b) you'll want to read up on ProcessBuilder, and c) you'll need to check your shell's man pages to see the exact syntax and arguments.
    runtime.exec("/bin/bash -c 'mv x/* y'");

  • Dos command in java

    Hi
    I have used google to get an answer for this.
    This is the command i have used to run some dos commands in java
    Unfortunately it doesn't throws any exceptions but still the directory and the file news.txt is not created.
    Process t=objrun.exec("command.com /c dir > c:/news.txt");
    Process p=objrun.exec("command.com /c mkdir c:/Prabhath");
    Please help me....am using windows xp OS.

    Note that the java.util.File has the following methods that might do the job :public File[] listFiles()
    public boolean mkdirs()
    public boolean createNewFile()

  • Clearing the DOS Window in Java

    hi
    I want to clear the dos screen using java.
    I saw 2 solutions on the net(given below) , but both did not work. Can someone advise how I can go about doing this ? I'm
    working on Windows2000.
    Thanks in advance.
    Seema
    1. char esc = 27; // ESC code
    String clear = esc + "[2J" // note case
    System.out.print(clear); // Dos screen should be cleared
    2. Runtime.getRuntime().exec( "cmd.exe /c cls" ) ;

    The escape code approach would only work on DOS windows that are processing ANSI escape sequences. This is something people used to enable all the time back in the pre-Windows days, since it was the only way to do things like clearing screens, setting colours, drawing menus out of text characters, etc. Ansi.sys still exists, at least on Win98 (not sure about NT, 2000, etc.). If you troll through the Microsoft web site or hunt down old books on DOS, you'll be able to find out how to set it up and use it.

Maybe you are looking for

  • How to display multiple lines in a text box defined in  steploop.

    Hi, I have a requirement to display data ( which is dynamic in nature. I determine data type,length etc dynamically) in a table format. I am using step loop for the same. I am facing a problem. Some field can be as long as 256 char long. Is there  an

  • Error while writing to file

    Hi all,i am trying to write some data into a file using utl_file.But i am getting UTL_FILE.WRITE_ERROR Here are the details '    v_file_name := 'File'||TO_CHAR(SYSDATE, '_DDMMYYYY_HH24MISS')||'.csv';       v_file_handle := UTL_FILE.FOPEN(p_file_dir,

  • Autocad to Acrobat PDF time out?

    I have atocad 2008 LT, Acrobat 9 standard on a windows 7 machine.  Printing to pdf from autocad was no problem until recently...  now, after maybe 20 prints, it times out and no longer allows me to print to pdf.  I have to completely restart the mach

  • LSI HDA Modem and Windows Fax and Scan

    Has anyone been able to send faxes with the above modem and Windows 7? I keep getting a "fatal error" message. Thanks,

  • Still No Battery Usage Stats

    Hi folks, I've seen lots of posts on this but still haven't seen a good answer. I have had my iPhone since launch day. I haven't hacked it once. I've updated to 1.0.1 and 1.0.2 on the evenings those updates came out. My battery usage stats continue t