Windows program problem using Runtime.

I have a program that works with the mouse click,
but does not work from a DOS command prompt.
It seems in Java the command exec works like DOS.
Anyway to overcome this?
Thanks.
boolean bWait = true;
try {
String cmd = System.getProperty("user.dir")+getString("Program");
Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmd);
BufferedInputStream bis =new BufferedInputStream(pr.getInputStream());
int c=0;
/** Outlet for IO for the process **/
while ((c = bis.read()) != -1) {
System.out.print((char)c); // do your processing
/** Now wait for the process to get finished **/
if(bWait == true) {
pr.waitFor();
pr.destroy();
} catch(Exception f) {
System.out.println("Could not execute process."+f+"\n");

Other than this.
C:\>cmd.exe /?
Starts a new instance of the Windows 2000 command interpreter
CMD [A | /U] [Q] [D] [E:ON | /E:OFF] [F:ON | /F:OFF] [V:ON | /V:OFF]
[[S] [C | /K] string]
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
/D Disable execution of AutoRun commands from registry (see below)
/A Causes the output of internal commands to a pipe or file to be ANSI
/U Causes the output of internal commands to a pipe or file to be
Unicode
/T:fg Sets the foreground/background colors (see COLOR /? for more info)
/E:ON Enable command extensions (see below)
/E:OFF Disable command extensions (see below)
/F:ON Enable file and directory name completion characters (see below)
/F:OFF Disable file and directory name completion characters (see below)
/V:ON Enable delayed environment variable expansion using c as the
delimiter. For example, /V:ON would allow !var! to expand the
variable var at execution time. The var syntax expands variables
at input time, which is quite a different thing when inside of a FOR
loop.

Similar Messages

  • HT5639 At present I have Windows programs installed using parallels 7. I now wish to delete all Windows based programs and revert the hard drive back to its original state ie single partition.  How do I go about it??

    At present I have windows based programs installed using parallels 7 on my Imac. I now wish to delete all the Windows programs etc and revert the Hard Drive to its original setting i.e single partition. How do I go about it??

    It's not clear if you installed Windows in a virtual machine or you installed Windows in Boot Camp but you run it in Parallels.
    If you installed Windows in Boot Camp, open "Boot Camp Assistant" (it's in /Applications/Utilities) and follow the steps to restore your hard disk into one volume. If you installed Windows on a virtual machine, just open Parallels and delete the virtual machine where you have installed Windows

  • Problem using Runtime.exec()

    hi all,
    I have a problem in executing the program which in turn runs the batch file which to deploy an EJB in IAS(application server).
    pls go through the code
    import java.io.*;
    public class ExeBat
    public static void main(String[] args)
    try
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("dsg07.bat VitalsignsGroup");
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader in1 = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    int s = in1.read();
    while(s!=-1)
    System.out.print((char)s);
    s = in1.read();
         catch(Exception e ){System.out.println(e);}
    In this program dsg07 is the batch file that executes deploys an ejb and VitalsignsGroup is the name of the jarfile. During the execution this Jar file is used to generate the stubs and skeletons during which it hangs.
    I hope u understood my problem and will suggest the solution.
    Thanks In Advance
    Parimala

    try running it as Runtime.getRuntime.exec("cmd abc.bat vitalgrp"

  • How to wait till the end of DOS program started using Runtime.exec(cmd)?

    In my Java program I need to call two DOS batch programs namely call.bat and start.bat. First I need to start the batch program call.bat and once that program is completed, I need to call the other batch file start.bat.
    The piece of code which I am using is:
    public static void ExecuteScripts(){
    try {
    \\Start the first batch program call.bat
    Process p = Runtime.getRuntime().exec("cmd /c start .\\scripts\\call.bat");
    p.waitFor();
    System.out.println("Exit value "+p.exitValue());
    \\Start the second batch program run.bat
    Process p1 = Runtime.getRuntime().exec("cmd /c start .\\scripts\\run.bat");
    catch (Exception e) {
    e.printStackTrace();
    For this piece of code it starts the first batch program(i.e, call.bat) in a command prompt and immediately it starts the second batch program (i.e, run.bat) in another command prompt. So it runs both the batch programs simultanesously. But what I wanted is that my program should wait till the first batch is executed and then start the second batch.
    Please tell me how to wait between these two runtime commands in JAVA
    With regards,
    C.Chenthil.
    -------------------

    Hi everybody thanks a lot.
    I got a solution from another forum. Kindly find the solution
    public static void ExecuteScripts(){
    try {
    \\Start the first batch program call.bat
    Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat");
    p.waitFor();
    System.out.println("Exit value "+p.exitValue());
    \\Start the second batch program run.bat
    Process p1 = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\run.bat");
    catch (Exception e) {
    e.printStackTrace();
    Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat"); is the switch that served my purpose.

  • Problems with runtime.exec()

    Hi All,
    I am having a problem using runtime.exec()
    in servlet to call a java file from the server.The server is a linux one and i am using a tomcat server-4.1.24 the server contains
    some java files which i need to invoke with the help of the servlet program so i try to use exec() in servlet to invoke a particular java file in the server.The program is compiling well but no information
    is displayed on the browser.Where in the servlet program i try to print the details of the particular java program that is in the server.For ur
    reference i will post the code :-
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    public class ExeServlet extends HttpServlet
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
    try
    String path = getServletContext().getRealPath("/var/jakarta/webapps/examples/WEB-INF/classes/ServletExample.java");
    /*Where it is the path of the java file that resides in the server machine(linux)Which i want to invoke and print its details on the browser*/
    Runtime runtime=Runtime.getRuntime();
    Process proc=runtime.exec(path );
    BufferedReader br=new BufferedReader(new InputStreamReader(proc.getInputStream()));
    res.setContentType("text/html");
    PrintWriter pw=res.getWriter();
    pw.println("<b>");
    String line=null;
    while((line=br.readLine())!=null)
    { pw.println(line); //Displaying the details of the ServletExample.java file in the browser
    pw.println("</b>");
    catch (Exception e)
    pw.println("Listener *not* started!");
    What is the problem here?I was so frustrated with this.Pls. do provide an immediate reply if there is any code regarding this is working pls. do provide it.It is Urgent.I will be waiting for ur reply.
    Thanx,
    m.ananthu

    Hi Leo,
    Thank u for the reply i still have the problem with exec() in servlets.Has i said earlier in my previous mail by using exec() i trying to execute the output of a c-program for eg,Hello.run which provides an output of "HelloWorld" which is a sample eg.The Hello.run is the directory /var/jakarta/webapps/examples/WEB-INF/classes which is also the directory where my servlet program is.Where i am using a tomcat server-4.1.24 on the linux machine 7.3.Which is the server ofcourse.
    Here by using a servlet program i try to exceute the Hello.run c-program and display the output in the browser.This is what i need to do.
    I also used a sample core java class put the exec() there in a method and i try to call the method in the servlet.Which is also not working.
    Here is that example :-
    The core java program:-
    public class UsingExec
    public String ExeDisplay()
         try
    System.out.println("ExeDisplay");
         Runtime rt=Runtime.getRuntime();
         Process p=rt.exec("/var/jakarta/webapps/examples/WEB-INF/classes/Hello.run");
    p.waitFor();
    return "true";
         catch(Exception e)
    return "false";
    public static void main(String args[])
    UsingExec ue=new UsingExec();
    ue.ExeDisplay();
    When i run this program only ExeDisplay at the top is displayed.
    Here is the Servlet program:-
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    public class ExeServlet extends HttpServlet
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
    try
    res.setContentType("text/html");
    PrintWriter pw=res.getWriter();
    UsingExec ue=new UsingExec();
    String line=ue.ExeDisplay();
    pw.println(line);
    catch (Exception e)
    When i display this program on the browser only "false" is displayed from the UsingExec.java & nothing is displayed.
    Thanx,
    m.ananthu

  • Converting Windows programs for Mac?

    I am considering purchasing a Mac, but have many expensive programs for Windows. I do not want to install Windows on my Mac. Is there a way to convert my Windows-compatible programs for my new mac computer?

    Hi and welcome to Discussions,
    while it is not possible to simply 'covert' a Windows program so that it runs in Mac OSX, you might wanna have a look at Crossover for Mac http://www.codeweavers.com/products/cxmac/ which lets you run certain Windows programs on a Mac without the need to install Windows.
    Depending on what Windows programs you use this approach is the 'least invasive way'
    regards
    Stefan

  • Running Windows programs in OS X`

    Somebody told me that OS X has been capable of running Windows programs for the past year. It was something that Steve Jobs said in his keynote speach a while back.
    I was wondering if anyone has done this, and how do I go about doing it?
    Something about Rosetta or something?

    OS X has been capable of running Windows programs by using VirtualPC, a commercial program that has been around for many years. I think what you're remembering was that Steve said Apple has been building special versions of OS X for use on Intel-based machines for the past year (several, actually). Rosetta is a program that lets programs built for PowerPC (the standard OS X machines) to run on these Intel-based machines as well. That way if you buy an Intel-based Mac, you can still use older software instead of having to buy new stuff specifically written for the new hardware.

  • Photoshop elements 12 editor doesn't open, organizer is fine. I uninstalled the program and re-installed it (restarted the computer each time)...didn't solve the problem. using pc, windows 8.1

    photoshop elements 12 editor doesn't open, organizer is fine. I uninstalled the program and re-installed it (restarted the computer each time)...didn't solve the problem. using pc, windows 8.1
    can someone help me with this issue?

    Two suggestions:  the first one is a workaround. You just have to drill down your program file tree to Adobe Photoshop Elements Organizer and find the .exe file - the one specifically for Organizer, not Elements.  Make a shortcut to that file on your desktop and it will open Organizer. The second suggestion resolved the problem altogether for me. I actually called Dell and after working with several different techs over several different days, I talked to a tech in premium support who was excellent. I discovered from them that it is actually a problem with the windows system files. I have 8.1.  I went through a "refresh" on my computer which rebuilt all the files. Then reinstalled Adobe as well as my other programs again and Photoshop Elements Organizer works from the standard desktop shortcut.

  • Issue regarding creating a process using Runtime in Windows 2003.

    Hi all..
    I need to resolve a small issue related to execute an external program using runtime execution method. But when i deploy the code in websphere application server 6.1V in windows 2003 server operating system, it is starting a process with min priority and not executing even i specified waitfor method.
    The code is like below.
    try{
    Process p = Runtime.getRuntime().exec("C:\\CopyImages.exe "+toWrite);
    int ep = p.waitFor();
    System.out.println("process "+ep);
    catch(Exception e)
    e.printStackTrace();
    Please help me in resolving this issue. The above code is working in my IDE which is in Window XP but when i port it in application server in windows2003 i'm getting this issue.

    hi..
    it is a typo error. i've given the slashes with that.
    but still getting the problem.

  • New "Windows Programming Using Java" Website

    Our newly created "Windows Programming Using Java" website (http://fivedots.coe.psu.ac.th/~ad/winJava/) is for programmers who want to extend Java's capabilities on Windows XP and/or Vista, but aren't sure where to start. One of the drawbacks of Java's portability is that many Java programmers have a rather sketchy knowledge of Windows-specific programming.
    We plan to explain how Java applications can utilize Windows application software, OS features, and hardware beyond the reach of Java's standard libraries. A variety of Java/Windows programming techniques will be explained, including:
    * Java's employment of the Win32 API via C, JNI, and J/Invoke.
    * Java's utilization of Window's Command Line Interface (CLI) and batch files, accessed through Java's Runtime, ProcessBuilder, and Process classes.
    * Java and Windows object-based scripting, centered around the use of VBScript, Windows Script Host (WSH), and Windows Management Instrumentation (WMI).
    * Java interoperability with COM, including hosting of ActiveX controls in Swing containers using jacoZoom.
    This website is a work in progress, with four chapters available for download at the moment. We'll be adding more regularly, and would love feedback on what we're doing.
    Thanks,
    Gayathri Singh and Andrew Davison
    [email protected] and [email protected]
    Edited by: AndrewDavison on Jun 20, 2008 1:36 AM

    Hi, I am looking the similar kind of requirement that you had done.. Do you have any more details on the code that is working for you . All i need is if the user logs in successfully in windows, the the app should be accessible. Please let me know if you have the code with you on this problem.
    Thanks in advance
    "what i meant is the we b applications running in my system, when i access the application iam able to to login automatically with windows authentication and now in case of other users following process happened:"

  • Problem of executing a process under Linux using Runtime.exec

    Hi, All
    I am having a problem of executing a process under Linux and looking for help.
    I have a simple C program, which just opens a listening port, accept connection request and receive data. What I did is:
    1. I create a script to start this C program
    2. I write a simple java application using Runtime.exec to execute this script
    I can see this C program is started, and it is doing what it supposed to do, opening a listening port, accepting connection request from client and receiving data from client. But if I stop the Java application, then this C program will die when any incoming data or connection request happens. There is nothing wrong with the C program and the script, because if I manually execute this script, everying works fine.
    I am using jre1.4.2_07 and running under Linux fedora 3.0.
    Then I tried similar thing under Windows XP with service pack2, evrything works OK, the C program doesn't die at all.

    Mind reading is not an exact science but I bet that you are not processing either the process stdout or the stderr stream properly. Have you read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html ?

  • Problem wiht Running Batch File using Runtime.exec()

    I am writting one program which will create a jar file using a windows Batch file.
    The main program is in the folder "d:\CmdExec.java".
    The other one to which a jar file to be created is in the folder "e:\folder\HelloWorld.class"
    The contents inside the "e:\folder" are
    e:\folder\HelloWorld.class
    e:\folder\mainClass.txt
    e:\folder\run.bat
    The mainClass.txt contains "Main-Class: HelloWorld"
    The Run.bat file contains "jar cmf mainClass.txt HelloWorld.jar *.class"
    The coding for CmdExec.java is as follows
    import java.io.*;
    import java.awt.Desktop;
    public class CmdExec {
    public static void main(String argv[]) {
    try {
    Desktop desktop = null;
    if (Desktop.isDesktopSupported()) {
    desktop = Desktop.getDesktop();
    desktop.open(new File("e:\\folder\\run.bat"));
    catch (Exception err) {
    err.printStackTrace();
    When i double click the file e:\folder\Run.bat, it will create a jar file for HelloWorld.class.
    But, i want to create that jar file using the java program CmdExec.java.
    When i run CmdExec.java, the batch file is opened. But it shows error as "Can't find the specified file"
    But when i copy the following files to "d:\",
    e:\folder\HelloWorld.class
    e:\folder\mainClass.txt
    the jar file is created using the CmdExec.java.
    But,
    e:\folder\HelloWorld.class
    e:\folder\mainClass.txt
    these files should be in the folder"e:\folder" only.
    Can anyone Help me this Problem?
    Or Anyother way for creating a jar file for one program by using another program?
    Help me soon.............

    Try this. It's not running a bat file. You can say it almost is a bat file.
    import java.io.*;
    import java.util.Scanner;
    public class CmdExec {
        public static void main(String argv[]) {
            try {
                Process p = Runtime.getRuntime().exec("jar cmf mainClass.txt HelloWorld.jar *.class");
                Scanner s1=new Scanner(new InputStreamReader(p.getInputStream()));
                while(s1.hasNextLine())
                    System.out.println(s1.nextLine());
                p.waitFor();
                System.out.println(p.exitValue());
                if(p.exitValue()==0)
                    System.out.println("Okay");
                else
                    System.out.println("Error");
            catch (Exception ex) {
                ex.printStackTrace();
    }Run it in the same folder as mainClass.txt
    Edited by: ColacX on Aug 1, 2008 10:35 AM

  • 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);
         }

  • Problems installing Windows XP Pro using Boot Camp

    I bought a MacBook this week for the purpose of running Windows XP off a partition. I ran the Boot Camp Assistant, partitioning 15 gig of my 160 gig hard drive for the Windows OS. Boot Camp prompted me to insert the Windows XP Pro with Service Pack 3 installation disc I'm using, so I did. I followed the Boot Camp instructions exactly, and the installation seemed to be on its merry way ... until the screen indicated there were 33 minutes left.
    With 33 minutes to go, the screen seemed to freeze (except that I could move the cursor/mouse) but the installation never advanced. I waited about an hour and it was the same, so I held the power button down and restarted the computer. It booted in Windows and tried to resume installation with 39 minutes to go. When it got to 33, it hung again.
    I've noticed other people having problems with this, but no solutions. Any ideas, folks?
    I want to be able to boot into Windows XP, not use Parallels or any other program.
    Any help is much appreciated. Thanks in advance.

    Sounds like your OS is dirty. Odd for a new product. I suggest try holding down Command S at start-up to open into single user mode. You get a black screen with text only. Read the lower portion of text giving you disk mount instruction fsck -fy (in Leopard and Tiger). type the code, press enter and the computer runs a whole series of Unix scripts for cleaning system, files and disk function. After several minutes the text concludes with the words ‘The volume (name of your volume) appears to be OK.’
    If so type exit and the computer opens into OSX.
    If the message reads ‘The volume (name of your volume) has been modified’ that means settings are incorrect. Type the fsck -fy again, press Enter, let the system run and the result will be volume appears OK. type Exit and your back into OSX.
    This bit of Unix code is invaluable for tuning up your system directories etc into sound condition. You will find an immediate speed increase. Having done this try your Boot Camp/ Windows install again. I hope it works, Good Luck.

  • Vista: use the windows program manager to execute operating system commands

    attempting to run forms 6 on vista... the forms app attempts a call sqlplus using the host builtin to populate some tables before calling the report.
    in windows vista i get a message box indicating "use the windows program manager to execute operating system commands".
    is this windwos vista message? would this have to do with permissions?
    any insight most appreciated and thanks in advance.

    I don't know about the HOST-problem, but..
    the forms app attempts a call sqlplus using the host builtin to populate some tables before calling the report.What about putting the logic from the SQL*Plus-scripts into a database-procedure and call that instead. I think,, with the current approach you will get problems at least when you have to migrate to Web (e.g. Forms 10g).

Maybe you are looking for

  • Oracle parallel server redhat 6.2/oracle 8.1.7 on 1 piii server/ 3 ppro clients

    hi, what a bloody maze! i have two immediate problems: 1) node db instances are unable to access control file raw devices on server; 2) opsctl (opsd) command returns: error in loading shared libraries: libskgxp8.so has invalid ELF header. please advi

  • How to add pdf files in your i phone without using Open in ibooks

    1. Sync your iphone with itunes. 2. Drag the pdf file on your system and simply drop it on your itunes icon. 3. pdf file automatically gets saved in your books folder. 4. Then you have to select the respective file and sync it. 5. File will be shown

  • New analysis XML customizedcriteria 11.1.1.5.0

    Hi, I create an analysis and I change subject area in XML with a presentation variable. So I have one report for different subject areas (Subject area's have same dimensions but different members, so my report works fine). Depending prompt it shows e

  • Requirement in Cell Editor

    Hello Guys, I am having one requirement in Cell Editor. My report is static report. I mean all the columns and rows already decided. My infoprovider is contain only one characteristics and two key figures. My characteristic is Circle and the Key Figu

  • How to read the code of html page

    Hi, I want to know how to read the code of html page through Java? And if anyone know the link of full implementation of Page Rank Algorithm in Java. Please let me know. I have to do the project on that topic. Regard Vivek