How to execute dir dos command in Runtime Execution

Hi All,
Does anybody know how to execute the dir command in DOS in the runtime execution
for example,
when we open the command prompt,
c:\Documents and Settings\java> e:
e:\cd java
e:\dir *.*
how we can list the directory in runtime execution?

Process childProcess = Runtime.getRuntime().exec("cmd /C dir *.*");or try with
ProcessBuilder pb = new ProcessBuilder("cmd /C dir *.*");
Process childProcess = pb.start();
NOTE: We can use the ProcessBuilder class from J2SE 5.0+.
for further reference check the below link
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=3
and don't forget to go through API documentation for java.lang package
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/package-summary.html
and if you want to implement it through Java which provides you a list of Files & directories in the present directory here is an example of such code snippet REF:as insisted by my fellow poster.
File file = new File("<present_directory_path>");
if(file.isDirectory()){
   String fileNames[] = file.list();
        for(String fileName:fileNames)
           System.out.println(fileName);
  fileNames = null;
        or for detailed info use
         File files[] = file.listFiles();
         for(File fileEntity:files)
            System.out.println("FILENAME:"+fileEntity.getName+",IS FOLDER:"+fileEntity.isFolder()+",ABSOLUTE PATH:"+fileEntity.toString()+"FILE SIZE:"+fileEntity.length());
         files = null;
}and please do not forget to go through File API Documentation provided as recommended by my fellow poster.
hope this might help :)
REGARDS,
RaHuL

Similar Messages

  • How to execute MS DOS command through Java program???

    Dear Sir,
    I want to run a MS-DOS command through my Java program. I have tried "Dir" command but no other command which takes command line args doesn't work at all. Please help.
    import java.io.*;
    class CommandPrompt
         public static void main(String[] args)
              try
                   File file = new File("C:/Temp/Java");
                   String[] cmd = {"command.com","/c","md folder"};
                   String[] envp = {""};
                   Process m;
                   String s = "";
                   m = Runtime.getRuntime().exec(cmd,null,file);
                   BufferedReader buf = new BufferedReader(new InputStreamReader(m.getInputStream()));
                   while ((s = buf.readLine())!=null)
                        System.out.println(s);
              catch (Exception ex)
                   System.out.println("Exception is "+ex);
                   ex.printStackTrace();

    1. This forum is for Swing-related issues only. This question should be posted to the "Java Programming" forum.
    2. Please enclose your sample code in code blocks; it's much easier to read that way. See here for how it's done: http://forum.java.sun.com/faq.jsp#messageformat
    3. Please provide more information, like what error messages you got and what OS you're running. For instance, if you're running WinXP, Win2k or NT4, your command processor should be "cmd.exe", not "command.com". When I made that change, your program worked for me.

  • Execute a DOS command in java

    Hi all,
    Is it possible to execute a DOS command in java? If so, how do I do that?
    Also, if it is a Linux machine, may I execute a Linux command in java?
    Thanks for your help.
    Regards,
    Bernard

    First, define 'command'.
    You can run external programs with Runtime.exec (eg. Runtime.getRuntime().exec("notepad");) but there are a few drawbacks regarding that method.
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Executing a DOS Command from JSP

    How do i execute a Dos command from within JSP. I would like to execute a sql Loader command .
    Thanks

    You use Runtime.execute().
    Take a look here for a few of the tricks involved in it:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to execute a system command with call executable in teststand 4.2.1?

    Hi All,
          how to execute a system command with "call executable" step in teststand 4.2.1?
          example as i want to quit a application.using "taskkill /f /im xxx.exe".And execute other system command(DOS).
    BR
    Johnny

    Hi, 
    I want to run netstat -an | find "8080" command from command prompt using call executable in test stand. after that i would like take the std output to local variable. 
    Attachments:
    callsettings.jpg ‏404 KB

  • Execute a dos command

    I am trying to execute a dos command thru sap and specific the delete command.
    i tried in 2 ways (i read it to the forum) but i can't do it.
    a)            DATA : FILE(100),
                   PARAM(50),
                   COMM(30).
                   COMM = 'DEL.COM'.
                   CONCATENATE 'C:\' 'A.TXT' INTO FILE.
                   CALL FUNCTION 'GUI_RUN'
                   EXPORTING
                   COMMAND   = COMM
                   PARAMETER = FILE.
    b)  CALL METHOD cl_gui_frontend_services=>execute
      EXPORTING
       DOCUMENT               = 'C:\A.TXT'
        application            = 'YDEL'
        parameter              = 'C:\A.TXT'
       DEFAULT_DIRECTORY      =
        MAXIMIZED              =  'X'
       MINIMIZED              =
       SYNCHRONOUS            =
        OPERATION              = 'OPEN'
      EXCEPTIONS
        cntl_error             = 1
        error_no_gui           = 2
        bad_parameter          = 3
        file_not_found         = 4
        path_not_found         = 5
        file_extension_unknown = 6
        error_execute_failed   = 7
        synchronous_failed     = 8
        not_supported_by_gui   = 9
        OTHERS                 = 10.
    Please help me ...

    Hi dimath,
    1. sorry, now this will work.
       (this will not even open the dos window)
      (it will get opened only for a fraction of seconds, and then get closed automatically)
      the file will get deleted.
    2.
    command = CMD
    parameter = /C DEL D:\AA.TXT
    (note /C is important)
    regards,
    amit m.

  • Execute MS-DOS command in Transaction

    Hello,
    I am copying encrypted files from the ftp server with the action: FTP Input.
    This works fine, but after this action i want that it executes a dos command from xMII to decrypt the files. I have a statement like this:
    raes-1.exe -d %TEST% DELFOR_20080507095802864.aes DELFOR_20080507095802864.xml
    I already tried some things, but i do not use a htm page or javascript. I want only the functions in a transaction and schedule this transaction. It has to look every day if their are files. Copy and decrypt them.
    When i executed through windows --> start --> run it works, so somehow it should also be possible to execute the command through MII.
    Kind regards,
    Nick
    Edited by: N. Meuter on Oct 17, 2008 3:38 PM

    I have developed it on my own system and uploaded it through the xmii menu custom action blocks.
    Now i deleted the action block and wanted to upload it again. But it did deployed directly. Where should i clear java? On my own computer or server?
    My java console on local machine says this:
    JNLP JREDesc in Component ignored: null
    JNLP JREDesc in Component ignored: null
    JNLP JREDesc in Component ignored: null
    ConsoleLogger::Creating NEW instance...
    WARN - Could Not Load Muffins, Using Defaults: http://smnlxmii2:50000/XMII/CMSLogicEditor/LookAndFeel
    <<< frog.jar: version 5.4.6  02/01/06  sap.theme: Tradeshow >>>
    Unable to localize label 'null', null
    Unable to localize label 'null', null

  • How to execute a DOS PROGRAM as batch file  in java

    How to execute a DOS PROGRAM as batch file in java
    pls help me

    www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to execute Operating System commands from Stored procedure.

    Any help on how to execute Operating System commands from stored procedures will be appreciated.
    Nanditha.

    Search the forums for 'External Procedure' and you will find example code that has been posted before.

  • How to run multiple DOS commands from a single Webutil Client_Host session?

    Hello all,
    I have a requirement where I need to create an interface with SVN from Forms for basic checkin-checkout of files.
    So, I've been trying to use webutil client_host to open a command line session and issue svn commands.
    For svn, sometimes I need to give multiple commands like change to a particular directory and then run an svn command.
    But client_host takes in only one command at a time and I'm unable to issue a series of DOS commands to perform
    a particular task.
    Is there a way to do this?
    Pls suggest.
    Regards,
    Sam

    First your original question... You can put more than one DOS command on a single line, simply separate each command with an ampersand (&). For example:
    mkdir c:\abc & cd abc & dir*
    Regarding your concerns about performance, well that would depend on exactly what you mean. Using CLIENT_HOST (or HOST on the server) simply opens a shell (DOS in this case) then passes your command to it. The performance of performing this action really isn't measurable. Basically you are just pressing a button and you should get a near immediate action. As for the performance of executing each command, that has nothing to do with Forms. Once the command is passed to the shell, the rest is a function of the shell and whatever command you passed.
    Having said that, if you were to write something sloppy like a loop (in pl/sql) which called CLIENT_HOST lots of times repeatedly, then yes there would be a performance problem because the pushing of the button will cause an exchange to and from the server and each cycle in the loop will do the same.
    So the answer to how performance is impacted will depend on what exactly you need to accomplish. If it is a single call to CLIENT_HOST, this should be fine.

  • How to execute a shell command?

    What class and method should I use to set an environment variable on a local system? And how do I execute a shell command in Java?
    Thanks!

    I don't know about setting environment variables from java, but I do know how to execute system commands (and from there you could modify environment variables).
    Use Runtime.getRuntime().exec()
    There are quite a few pitfalls with using this though...
    1. It's platform dependent
    2. Doing this creates a Process. If this process has output, you need to read this, otherwise the output buffer will overflow, and that would be bad... Input is not so bad (either supplying it or not ;)
    3. If you use Win for example, and want to do a "dir", there are complications, as there is no dir.exe file, and hence it can't be executed... Do a search for this topic, there's plenty on how to get around it.
    Anyway, there's plenty more info on Runtime.getRuntime().exec(), have a look around.
    Cheers,
    Radish21

  • How to execute a Unix Command in java

    Hi, Iam trying to execute a unix command on Sun Solaris by passing that command to a java program. How can I achieve this?
    Thanks in advance.

    Have a look at the javadoc around the Runtime.exec() method. If the command is a shell command then you might have to execute a shell as well as the command.
    For example, if you wanted to run a unix command 'ls -l > output.txt' the you might have to pass the following string into the exec() method,
    "/bin/sh ls -l > output.txt'

  • How to launch a DOS command with process

    When I tried to create a process which launch a DOS command, I have a big exception with CreateProcess error=2.
    I just would like to make a "cd directory"
    Please help!!!

    Go back to the API documentation and look for the version of Runtime.exec() that allows you to specify the working directory. Even if you could run a task that executed "cd something" that would be pointless, since it would only change the current directory of that task.

  • 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

  • How to execute any cmd command from java application?

    Hi all,
    How to execute or call any command of cmd from java application??
    Is there any method to do so??
    Or, is it possible to do it using Runtime.exec() ??? And if so, how to use it, please explain with ab example...
    I'll highly appreciate....
    Thank you.

    If google would be the best option, then I would not be on Sun's forums and I would not have asked experts like you, sir !! :-)
    Neway, I got the solution from PhHein !!
    Good link indeed..
    Cheers..

Maybe you are looking for

  • Error: Couldn't find delivery channel for message

    Hi All, In our production environment, we sometime get the following error (Channel Audit Log): 2009-01-12 15:08:47 Error Unable to find channel ID 2009-01-12 15:08:47 Error Delivery of the message to the application using connection SOAP_http://sap.

  • Hiding the Set Top Box (STB) - What kind of cables do I need?

    I want to place my HD DVR STB in a nearby closet.  Will probably require 15-20 feet of cable to be safe.  I came across several different terms (Emitter, Blaster, RF, etc) but wasn't sure what I need.  This is a simple set up - just the cable box so

  • Is there a place I can still download CF10?

    I can only find downloadable files for CF11, is there a downloads area for earlier version?  I would like to download that latest/last release of CF10 if possible.

  • Does photo stream distribute also photos saved on iOS device?

    I have several photos taken by another iPhone and sent to my iPhone via email or whatsapp. I see them on my iPhone but not on my iPAD.

  • One site two separate menus ... is this possible?

    I am new to Muse and trying to create a new site. I have created a landing page and i want people to be able to navigate from the landing page to my other websites. To navigate to an external site is easy. But, what if I am essentially creating a sit