Can't execute a DOS program from a Java one

Hi everyone !
I'm a student, working as an apprentice in a company, and I have to make a program to execute faster some daily routine.
Here's my problem : I'm trying to execute a DOS program (mkisofs.exe) whick takes numerous arguments and enables me to create an ISO file.
But, for now, I can't manage to make it work. I've used both Process and ProcessBuilder, but in vain (I'm a student, and not really a JavaProgrammingStar).
If I would manually execute the command, I'll have to type under DOS the following command :
"C:\Documents and Settings\myName\Desktop\Current\Local\mkisofs.exe"   -r -J -l -L -b "isolinux/isolinux.bin" -c "isolinux/isolinux.cat" -no-emul-boot -boot-load-size 4 -boot-info -table -graft-points -o D:\ISO\toto.iso "C:\Documents and Settings\myName\Desktop\Current\Local\Clonezilla"or (without spaces)
C:\docume~1\myName\Desktop\Current\Local\mkisofs.exe   -r -J -l -L -b "isolinux/isolinux.bin" -c "isolinux/isolinux.cat" -no-emul-boot -boot-load-size 4 -boot-info -table -graft-points -o D:\ISO\toto.iso C:\docume~1\myName\Desktop\Current\Local\ClonezillaTill now, I've only managed to execute windowed program such as MsPaint.exe or DOS program from System32 directory such as taskkill.exe, but I couldn't execute, for example, tasklist.exe, or at least, I couldn't see the result of this command.
Can anyone help me ?
If some code is needed, jsut tell me.
Thanks by advance !
Hubert

Ok guys, I'm French, so excuse me if I didn't use the correct terminology, but I'm quite sure you understood that I was talking about MS-DOS command prompt in Windows XP.
Then, of course I've STFW, but none on my tries was successful. So a little help would be appreciated.
I've first tried this :
ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/K", "mspaint.exe");
                  pb.redirectErrorStream(true);
                  try {
                      Process p = pb.start();
                      BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                      try {
                          String rep = in.readLine();
                          System.out.println(rep);
                      } finally {
                          in.close();
                  } catch (IOException e) {
                      e.printStackTrace();//repTF.setText("erreur");
                  }It worked.
But this :
String CMD = "C:\\docume~1\\myName\\Bureau\\Current\\Local\\mkisofs.exe";
String arg1 = "-r -J -l -L -b \"isolinux/isolinux.bin\" -c \"isolinux/isolinux.cat\" -no-emul-boot -boot-load-size 4";
String arg2 = "-boot-info -table -graft-points -o D:\\ISO\\toto.iso C:\\docume~1\\myName\\Bureau\\Current\\Local\\Clonezilla";
ProcessBuilder pb = new ProcessBuilder(CMD, arg1, arg2);
                  pb.redirectErrorStream(true);
                  try {
                      Process p = pb.start();
                      BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                      try {
                          String rep = in.readLine();
                          System.out.println(rep);
                      } finally {
                          in.close();
                  } catch (IOException e) {
                      e.printStackTrace();//repTF.setText("erreur");
                  }does'nt.
What's wrong ? I should use a String table for args ?

Similar Messages

  • How can I execute a batch file from my java program

    Hi,
    Can someone help me or direct me to a link,
    How can I execute a DOS batch file from my java program?
    Thanks

    You will need to grab a handle to the process's
    outputstream so u can see its output.The OP didn't mention any output from any batch file;
    nor any input for that
    matter,so lets not complicate matters here for now
    ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
    I'm sure it wasn't intentional that your post appeared to be bristling with attitude.

  • How can I execute an external program from within a button's event handler?

    I am using Tomcat ApacheTomcat 6.0.16 with Netbeans 6.1 (with the latest JDK/J2EE)
    I need to execute external programs from an event handler for a button on a JSF page (the program is compiled, and extremely fast compared both to plain java and especially stored procedures written in SQL).
    I tried what I'd do in a standalone program (as shown in the appended code), but it didn't work. Instead I received text saying the program couldn't be found. This error message comes even if I try the Windows command "dir". I thought with 'dir' I'd at least get the contents of the current working directory. :-(
    I can probably get by with cgi on Apache's httpd server (or, I understand tomcat supports cgi, but I have yet to get that to work either), but whatever I do I need to be able to do it from within the button's event handler. And if I resort to cgi, I must be able to maintain session jumping from one server to the other and back.
    So, then, how can I do this?
    Thanks
    Ted
    NB: The programs that I need to run do NOT take input from the user. Rather, my code in the web application processes user selections from selection controls, and a couple field controls, sanitizes the inoputs and places clean, safe data in a MySQL database, and then the external program I need to run gets safe data from the database, does some heavy duty number crunching, and puts the output data into the database. They are well insulated from mischeif.
    NB: In the following array_function_test.pl was placed in the same folder as the web application's jsp pages, (and I'd tried WEB-INF - with the same result), and I DID see the file in the application's war file.
            try {
                java.lang.ProcessBuilder pn = new java.lang.ProcessBuilder("array_function_test.pl");
                //pn.directory(new java.io.File("K:\\work"));
                java.lang.Process pr = pn.start();
                java.io.BufferedInputStream bis = (java.io.BufferedInputStream)pr.getInputStream();
                String tmp = new String("");
                byte b[] = new byte[1000];
                int i = 0;
                while (i != -1) {
                    bis.read(b);
                    tmp += new String(b);
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + tmp);
            } catch (java.io.IOException ex) {
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + ex.getMessage());
            }

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

  • How Can I execute an external program from my vi?

    Hi guys,
    I want to execute a external program to use it when i called with a bottom. I want push a bottom and execute the program, like acess direct icon or so.
    Any help?.

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

  • 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

  • Running DOS program from java

    Hi all,
    I'm trying to execute a dos program using:
    runtime.exec("dos_prog.exe")
    THE PROBLEM : in this way I can run only
    WINDOWS programs and NOT DOS progs.
    What to do ???

    Hi all!
    I'm tring to run a file.bat that execute an exp from locale Oracle server. But when I run it, in dos consol it appaire just only the EXP USER/PASS ....., and don't execute never!! Really, the files of .dmp and of .log, they are created, ...but empty!!!! Why???
    ........ source .......
    Runtime rt = Runtime.getRuntime();
    Process rtProcess = rt.exec("cmd.exe /C file.bat");
    // wait for command to terminate
    try      {
         rtProcess.waitFor();
    catch     (InterruptedException ire)
         System.err.println("Thread interrupted " + ire.getMessage());
    // check its exit value
    if (rtProcess.exitValue() != 0)
    System.err.println("exit value was non-zero");
    // close stream
    bReader.close();
    ........ file.bat .......
    @echo off
    EXP USER/PSW FILE=EXPFILE.DMP LOG=FILELOG.LOG OWNER=MYOWNER
    If you want, you car reply me directly at [email protected] - Thanks very much!!!

  • How can I execute a  .bat  file from inside a java application

    I have a .bat file which contains an executable file(.exe) and some input and output file names. What commands can I use to execute this bat file from my java application.

    After raeding tkleisas' reply; i am trying to invoke another application (which can be invoked from the command line) by using a batch file and trying Runtime.exec for executing a batch file.
    My current code is:
    Runtime runtime = Runtime.getRuntime();
    Process trialProcess;
    trialProcess = runtime.exec("cmd.exe /C start C:\\guns.bat /B");
    And my guns.bat looks like:
    cd C:\CALPUFF
    echo trial
    start calpuff.exe CALPUFF.INP
    This is not working for me and i get the following in the error stream of the trialProcess:
    Error :
    The system cannot execute the specified program.
    Process finished with exit code 1
    Has anyone come across something like this and know what's wrong with this one??
    thnx

  • Oops - meant to say "Controlling Legacy DOS program from Java ..."

    Sorry - don't know what I wasn't thinking - muddled up my post title!
    As part of my final year project, I'm trying to control a camera mount automatically using stepper motors. This will then be used for robotic navigattion. Most of my code is written in Java, but I have been given some old C code to control the motors with. One loaded, it sits in an infinite loop that waits for keyboard input, resonds, loops, and so on ...
    I'm trying desperately to find a way of issuing commands to this program from my Java programs. I tried to implement a listening server in the C code but got a bit bogged down. Now wonder if I can use the
    exec and getOutputStream methods in Java to control the Dos program...?
    Any ideas very very welcome. I've reached hair pulling out time!
    Ben Barker

    Everything is now woeking...ish:
    I can now make the below java program bring up, for instance, windows calculator or notepad.
    I can't test it on the main code yet at I don't have the right computer in front of me. However, I decided to try to test it by runing cmd using ...exec("cmd"), then printing a command to the output stream to make windows calculator run. This caused precisely nothing to happen ...
    Any ideas?
    import java.io.*;
    class java_test
    public static void main(String[] args)
              try
              Process p= Runtime.getRuntime().exec("cmd");
              InputStream is= p.getInputStream();
              OutputStream os= p.getOutputStream();
              PrintStream printStr = new PrintStream(os);     
              printStr.println("calc.exe");
              catch (Throwable t)
              t.printStackTrace();
    }

  • I want to be able to execute a swing program from my  desktop

    i want to be able to execute a swing program from my desktop but i dont know how to go about it. Till now to run the programs i used command prompt. please can you guys help me cross this huddle. I need step by step solution to do this

    In Windows, you associate a .jar file with javaw. YOu can do this with a right-click on the system icon, if I recall correctly.
    Another option is to wrap the jar file in an executable wrapper so it looks like an .exe. I have used JSmooth to good effect for this.
    Good luck. It is only modestly tricky

  • Controlling legacy DOS program from linux

    Hi,
    As part of my final year project, I'm trying to control a camera mount automatically using stepper motors. This will then be used for robotic navigattion. Most of my code is written in Java, but I have been given some old C code to control the motors with. One loaded, it sits in an infinite loop that waits for keyboard input, resonds, loops, and so on ...
    I'm trying desperately to find a way of issuing commands to this program from my Java programs. I tried to implement a listening server in the C code but got a bit bogged down. Now wonder if I can use the
    exec and getOutputStream methods in Java to control the Dos program...?
    Any ideas very very welcome. I've reached hair pulling out time!
    Ben Barker

    I can see a couple of ways to do this.
    1. Using - as you suggested - exec and input stream/output stream.
    I suggest you write a really tiny java control program to test this. You can simply never tell what kind of input or output assumptions are built into the C code. (What I mean is, sometimes it is very hard to find somethng in the output you can use to control your java-sideparsing.
    2. An alternative is to turn the C code into a shared library (dll or so) with an appropriate Native interface and java object with methods declared "native". It sounds like your fundamental model is java calling C code, so if the interface only requires a few calls, then this could work well.

  • How can we disable the 'Improvement Program' from all the apps in TCS5?

    How can we disable the 'Improvement Program' from all the apps in TCS5, so that the end users are not able to see the option in the help menu?
    We have tried changing the value of bUsageMeasurement (HKLM\SOFTWARE\Policies\Adobe\(product name)\(version)\FeatureLockdown) to zero, but it did not help.

    You’re probably going to have to contact Support on that one.

  • JCO.Server Error while trying to execute a RFC program from SAP

    Hi,
    We are connecting to an external registered server program from SAP via Web Methods.
    The external server program is registered with the SAP Gateway. We have created a TCP/IP RFC destination and are able to connect to the destination successfully via SM59.
    An RFC function is created in SAP and is called using the syntax CALL FUNCTION "/NGN/BAPI_STRE_SEARCH_PROCESS" DESTINATION 'PRDB2B'. We have also handled the COMM_FALIURE and SYSTEM_FALIURE exceptions in the function call.
    We are monitoring the gateway via SMGW and see a connection log to the RFC destination as below
    Number - 10
    LUname - dev01
    TPName - sapgw00
    User - KRAORANE
    Status - CONNECTED
    Symbolic - PRDB2B
    Conversation - 86520353
    Prot - REG
    SAP return code - 0
    CPIC rtn code - 0
    The external program returns results as expected.
    However sometimes the RFC fails and returns the message “JCO.Server could not create server function /NGN/BAPI_STRE_SEARCH_PROCESS”.
    We are not able to figure what exactly is causing this error. Any help will be highly appreciated.
    -Kiran

    Hi,
    Please see the below links..
    JCO.Server Error while trying to execute a RFC program from SAP
    Re: JCO.Servcer could not find server function
    Re: JCO.Server could not find server function 'SET_SLD_DATA'
    /people/kathirvel.balakrishnan2/blog/2005/07/26/remote-enable-your-rfchosttoip-to-return-host-ip-to-jco
    Re: interfacing SAP with an existing java applications
    http://help.sap.com/saphelp_nw04/helpdata/en/47/80f671ee6e4b41b63c0fe46bd6e4f8/content.htm
    http://www.sapgenie.com/faq/jco.htm
    Regards
    Chilla..

  • Can we call a bdc program from report program

    hi
    can we call a bdc program from report program

    Yes you can any program from another program using
    SUBMIT <repname>   statement
    SUBMIT <repname> USING SELECTION-SCREEN dynnr.
    or
    SUBMIT <repname> VIA SELECTION-SCREEN USING SELECTION-SET variant
    SUBMIT <repname> VIA SELECTION-SCREEN WITH SELECTION-TABLE rspar
    etc.
    Regards
    Prax

  • How to start an executable program from a java program ?

    Hi,
    does someone know how to start an executable program from a JAVA program ?
    Thanks, Fred.

    Take a look at the Runtime class.
    -S-

  • Can I execute MySql's command from java application?

    Can I execute MySql's command from java application? And how?
    For example :
    load data local infile 'D:\\myData.txt'
    into table myTable
    fields terminated by ';'
    lines terminated by '\n';

    1. get the jdbc driver for mysql from the mysql site at: http://dev.mysql.com/downloads/connector/j/5.0.html
    2. follow the installation instructiions... which you'll also find in your mysql manual...
    Happy travels. Keith.

Maybe you are looking for