Issue DOS commands?

How do I issue DOS commands from within a Java program and retrieve the DOS output as input to the program?

See this JavaWord article for lots of detail and some
traps and pitfalls...
ChuckOh, and I suppose you wanted the link too... ;-<
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Similar Messages

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

  • Abobe 9: Printing a PDF file using a DOS command

    I have Adobe 9.4.0 on a server and would like to print PDF files using a DOS command. The DOS command we are using is:
    start Acrord32.exe /T/S/h/O "C:\BO_Archival_Code_Deployment\Print\TINF018_C.pdf" "Lexmark T644 PS3 - 10.192.36.126"
    With this, we are able to print only page 1 of the PDF file. The other pages remain unprinted. This means there is no issue related to printer configuration, firewalls, etc.
    Other observations:
    1) When we print the file manually after opening it in Adobe 9.4.0, all pages are printed.
    2) We found that the above command provides different results with Adobe 8.2.6 i.e. with the DOS command, all pages are printed while using Adobe 8.
    We are trying to automate some tasks for which we require the PDF files to be printed automatically through a DOS command. We are being advised to use Adobe 9 as technical support for Adobe 8 is likely to be withdrawn soon.
    Please can you help.

    Sorry. This is a forum for Adobe Connect issues not PDF issues. Please locate the correct forum so your question can be addressed properly there.

  • 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).

  • Problem while running dos command from java program

    Dear friends,
    I need to terminate a running jar file from my java program which is running in the windows os.
    For that i have an dos command to find process id of java program and kill by using tskill command.
    Command to find process id is,
    wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
    This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
    when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
    Code to run this command is,
    public class KillProcess {
         public static void main(String args[]) {
              KillProcess kProcess = new KillProcess();
              kProcess.getRunningProcess();
              kProcess = new KillProcess();
              kProcess.readProcessFile();
         public void getRunningProcess() {
              String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
              try {
                   Runtime run = Runtime.getRuntime();
                   Process process = run.exec(cmd);
                   int i = process.waitFor();
                   String s = null;
                   if(i==0) {
                        BufferedReader stdInput = new BufferedReader(new
                               InputStreamReader(process.getInputStream()));
                        while ((s = stdInput.readLine()) != null) {
                         System.out.println("--> "+s);
                   } else {
                        BufferedReader stdError = new BufferedReader(new
                               InputStreamReader(process.getErrorStream()));
                        while ((s = stdError.readLine()) != null) {
                         System.out.println("====> "+ s);
                   System.out.println("Running process End....");
              } catch(Exception e) {
                   e.printStackTrace();
         public String readProcessFile() {
              System.out.println("Read Process File...");
              File file = null;
              FileInputStream fis = null;
              BufferedReader br = null;
              String pixieLoc = "";
              try {
                   file = new File("ProcessList.txt");
                   if (file.exists() && file.length() > 0) {
                        fis = new FileInputStream(file);
                        br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
                        String line;
                        while((line = br.readLine()) != null)  {
                             System.out.println(line);
                   } else {
                        System.out.println("No such file");
              } catch (Exception e) {
                   e.printStackTrace();
              return pixieLoc;
    }     when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
    if i give process.waitFor(), then it's in running mode and program is not completed.
    Colud anyone please tell me how to handle this situation?
    or Is there anyother way to kill the one running process in windows from java program?
    Thanks in advance,
    Sathish

    Hi masijade,
    The modified code is,
    class StreamGobbler extends Thread
        InputStream is;
        String type;
        StreamGobbler(InputStream is, String type)
            this.is = is;
            this.type = type;
        public void run()
            try
                InputStreamReader isr = new InputStreamReader(is, "UTF-16");
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    System.out.println(type + ">" + line);
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    public class GoodWindowsExec
        public static void main(String args[])
            try
                String osName = System.getProperty("os.name" );
                String[] cmd = new String[3];
                 if( osName.equals( "Windows 95" ) )
                    cmd[0] = "command.com" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                } else {
                    cmd[0] = "cmd.exe" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd[0] + " " + cmd[1]
                                   + " " + cmd[2]);
                Process proc = rt.exec(cmd);
                System.out.println("Executing.......");
                // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERROR");           
                          // any output?
              StreamGobbler outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUTPUT");
                          // kick them off
                errorGobbler.start();
                outputGobbler.start();
                // any error???
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
            } catch (Throwable t)
                t.printStackTrace();
    }when i execute the above code, i got output as,
    Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
    and keeps in running mode only.
    If i execute the same command in dos prompt,
    CommandLine
    ProcessId
    java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP  2468
    If i modify the command as,
    cmd.exe /C wmic process where "name='java.exe'" get commandline,processid  > 123.txt
    and keeps in running mode only.
    If i open the file when program in running mode, no contents in that file.
    If i terminte the program and if i open the file, then i find the processid in that file.
    Can you help me to solve this issue?

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

  • Update BIOS from DOS command line?

    Hello, I'd like to be able to flash the BIOS from the boot prompt or with a USB/CD/DVD based tool. I cannot open any OS even from live DVDs. My Presario SR5507F came originally with Vista installed but over the years it was upgraded to Windows 8.1. It gave us years of reliable service but sometime last fall the PC started experiencing seemingly random reboots and powerdowns. Things got pregressively worse until the PC was unusable. It would run for 15 or 20 minutes and then reboot. The problems started shortly after a Windows update, so I thought this was a patch or driver update issue. I tried reverting an removing patches to no avail. I also tried installing Ubuntu and Fedora, but they exhibit the same issues. Fedora is worse than Ubuntu, though. I tried to reinstall Windows 8.1, then 7 and finally the original Vista 32-bit OS but all Windows installations fail at some point during drivers installation. The computer just enters an endless reboot cyle and Windows cannot be installed. I ran memory tests but they all pass and I can use a text based OS, such as DOS. I have tried to reflash the BIOS, thinking it may have been corrupted during one of the reboots, but since I cannot install any version of Windows, the BIOS flash tools refuse to work. I need to be able to flash the BIOS from the DOS command prompt or at boot. Is there such a tool from Compaq/HP? Thanks!

    The BIOS file is found on THIS PAGE and is listed asMCP61PM-HM Motherboard BIOS Update 5.271.5 MBAug 2, 2012sp40911.exe Open the download after it is complete with 7-zip by right clicking on the sp40911.exe, then extract the Net5.24 to a known location.  AWDFlash downloadJust rename the file to 524.bin and use awdflash from DOS.Use  awdflash 524.bin /cc/cd/cp/py/R

  • Calling DOS command from a webpage?

    How would I go about doing this? I want a webpage that when an image is clicked this DOS command is called:
    rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen Image_Location\image.jpgThis command opens the image in Windows Picture and Fax Viewer. I'm not worried about portability since this is only going to be on my home network. I figure I'll probably need Java or something to do this, but I've no clue where to start looking. Help is appreciated!

    How would I go about doing this? I want a webpage
    that when an image is clicked this DOS command is
    called:First of all, this is not a Java-related question. It is an HTML and browser capabilities question.
    Second of all, in general this is not possible. If it were, imagine the security issues allowing a web page to arbitrarily allow executing anything on the client victim's machine. At best the user has to configure his browser to "trust" content from the site in question. Since you as the application provider can't force this configuration to happen automatically, you're out of luck unless you are in complete control over the clients (such as if they are all within the corporate intranet only).

  • DOS Command Schtasks - error

    Hello,
    I am locally executing a batch file which contains the following:
    SchTasks /query /fo csv > C:\AllReports\Schedtask.txt /v /s AppServer.xyz.org
    I do get the ouptut file along with the requested info but I also get the following:
    ERROR: The task XML contains a value which is incorrectly formatted or out of range
    ERROR: Task cannot be loaded: UpsizeToSQL - Special Run - is the first line withing the output file. Subsequent lines show actual Schtasks results
    Appserver.xyz.org is a remote server I am able to access to using my network credentials. I am able to run Schtasks from the command line without issues and get a results clean of error messages. The issue appears when I execute the batch file from my local
    machine to retrieve tasks on that remote server.
    Any help to find a solution would be much appreciated.
    Thank you.

    Hello,
    I locally executing a batch file which contains the following:
    SchTasks /query /fo csv > C:\AllReports\Schedtask.txt /v /s AppServer.xyz.org
    I do get the ouptut file along with the requested info but I also get the following:
    ERROR: The task XML contains a value which is incorrectly formatted or out of range
    ERROR: Task cannot be loaded: UpsizeToSQL - Special Run - is the first line withing the output file. Subsequent lines show actual Schtasks results
    Appserver.xyz.org is a remote server I am able to access to using my network credentials. I am able to run Schtasks from the command line without issues and get a results clean of error messages. The issue appears when I execute the batch file from my local
    machine to retrieve tasks on that remote server.
    Any help to find a solution would be much appreciated.
    Thank you.
    Hi,
    Since this issue is mainly related to Dos Commands, I would recommend you refer to the following thread to get where to get supports for this issue.
    Where is the Forum for DOS Commands
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Too many DOS command windows

    Hello,
    When I start my local J2EE engine from inside the Management Console it launches a bunch of DOS command windows.
    Is there anyway to make those just go away after they have launched/started whatever process each of them handles?
    It's not a huge deal but it's annoying to see all those DOS windows on my Task Bar AND there is always the possibility that one of them will get closed by accident thereby "screwing up something".  It just seems kinda archaic to have all these DOS windows there the whole time I'm running my local engine.
    Thanks in advance for any help.
    David.

    Just cleaning up all my unanswered questions. Sorry that this will cause the post to 'bubble up' to top.
    When we upgraded to later versions of Netweaver Developer Workplace this was not an issue anymore.
    We're currently on 2004s sp09

  • Is it possible to call ms-dos command in abap program?

    Hi,
    is it possible to call ms-dos command in abap program?
    Thanks.

    Hi Cemil,
    You probably have your answer here:
    [Re: DOS/Windows command in app server;
    You create your external command with SM69 (you can test it with SM49).
    Then you call this command with function module "SXPG_COMMAND_EXECUTE".
    (See function group SXPT for all the calls to external commands).
    Regards,
    Thomas

  • Is there a way to run dos commands on onther system?

    Hi I have connected to a port of another system where windows is the operating system. So can I run dos commands on the other system through that network connection from my computer?

    I'm not sure what you mean by "connected to a port of another system" . Which port using what software to which server?

  • Where should I issue this command

    Hi all,
    I'm configuring a logical standby database (Oracle 10g R2 on Linux 4.5). In the steps, I should convert to a Logical Standby Database and thus the following command should be issued:
    ALTER DATABASE RECOVER TO LOGICAL STANDBY db_name;My question is: if I have db1 as the primary database and db2 as the standby one, on which database should I issue the command? what would be the value of db_name?
    Thanks in advance.

    I can sort of see why this section of the manual (http://download.oracle.com/docs/cd/B19306_01/server.102/b14239/create_ls.htm#i92346) where it says:
    This section describes how to prepare the physical standby database to transition to a logical standby database. It contains the following topics:
    and
    The redo logs contain the information necessary to convert your physical standby database to a logical standby database. To continue applying redo data to the physical standby database until it is ready to convert to a logical standby database, issue the following SQL statement:
    was not clear enough to state definitely that you do the command on the Physical Standby.
    The preceding section header says: 4.2.3 Prepare the Primary Database to Support a Logical Standby Database
    And then it goes to: 4.2.4 Transition to a Logical Standby Database
    I can see where it might look like we're still on the Primary database. I checked the 11.2 manual and it is pretty much the same so I'll file a doc bug to try and clean this up.
    Thanks.
    Larry

  • Execute DOS command in current window!

    All:
    Here is my code :
    import java.io.*;
    public class BuildScript {
    public static void main ( String[] args ) {
    String[] command = {"C:\\winnt\\system32\\cmd.exe", "cls"};
    try {
    Process process = Runtime.getRuntime().exec ( command );
    process.waitFor();
    } catch ( InterruptedException e ) {
    e.printStackTrace();
    System.exit(-1);
    } catch ( IOException e ) {
    e.printStackTrace();
    System.exit(-1);
    System.out.println ( "DONE!" );
    I just want to exeute some simple DOS command from Java application. And then I run this code, it hangs there for ever. I comments out "process.waitFor()", then it print out the "DONE" however it seems that it just open another console and clear that one and exit. For the main console I start my code, nothing happened.
    Can anyone help me out how to execute the dos command in current console window.
    Thanks

    Can anyone help me out how to execute the dos command in current console window.Sorry to say but there is no way to do that.
    The best way to clear the screen is to print a few hundred newlines.
    Trust me, this is a frequently asked question.

  • Is it possible to run dos-command's in java?

    I have a small security problem. I have a dos-based java prog. with login at the start og the program, but I have problems hiding the password. I have managed to hide the password when it is typed, but when you press enter and get to the next menu, it is only to press the up-key, and dos recover the last typed sentence. (The password...) I have been able to fine the dos-command "doskey /reinstall", which will clear the memory, but I haven't been able to implemet this in my java-prog.
    Any tips/trics are appreciated.

    I have a small security problem. I have a dos-based
    java prog. with login at the start og the program, but
    I have problems hiding the password. I have managed to
    hide the password when it is typed, but when you press
    enter and get to the next menu, it is only to press
    the up-key, and dos recover the last typed sentence.
    (The password...) I have been able to fine the
    dos-command "doskey /reinstall", which will clear the
    memory, but I haven't been able to implemet this in my
    java-prog.
    I doubt that calling that in your program would help.
    doskey is specific to the process. Running it by any means in java means that a new process will exist. You can verify this by open two console windows and running doskey in both. Nothing that you do in one will be reflected in the other.
    I don't think your problem is a program problem. That means that it should not be solved by software but rather by management. For example you certainly wouldn't expect your program to make sure that someone wasn't standing behind the user when they typed their password right? And what if someone installs a key grabber on the computer? In that case any program, yours included, would have all the key presses logged to a file.
    Alternatively if you might be able to solve it with one of the following...
    - Recode the application to use a GUI. If there is no console the doskey isn't going to get anything.
    - Write some JNI that bypasses the java input handling. If you handle the input directly then you can turn off echo
    - Inspect the java source code for the VM. There might be a hidden method to turn echo off. Alternatively you can find the code responsible for this, modify them, and use them with the bootclass option to replace the ones in the VM. This solution is not distributable. And it might not be possible solely using java.

Maybe you are looking for

  • How do I stop two sided printing

    How do I stop two sided printing?

  • Selecting and loading songs into an already full Nano (8G)

    Hello: I had loaded months ago my Nano with all my songs in the Library as it was less than 8G. Now I want to connect my Nano and 'reload' (not sure the right term) songs I want on it (along with Playlists). My current Library has many more songs now

  • How to import tablespace

    hi, anyone tell me how to import tablespace as i am repeatedly getting the different error. actually wat i did is during export i made the corresponding tablespace which i am going to export 'read only' and exported successfully. during import i drop

  • Installed Security Update 2013-003 & now cannot see video

    Installed Security Update 2013-003 & now cannot see video. Snow Leopard. Corrected problem by updating Adobe Flash~ even though I just updated it two days ago~ but that solved the problem. Message was edited by: Black Cat Prowl

  • HTTP_RESP_STATUS_CODE_NOT_OK -- 500 -- Timeout

    Hi Guys, There is 1 msg gone to error status with below error . <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <!--  Call Integration Server   --> <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30"     xmlns:SOAP="http://schemas.xmlso