Running a DOS Command through a JAVA GUI

I'm trying to run a command line through a GUI.. how would i go about doing this... suppose i wanted to run the following dos command inside a java program:
String command = "jar cvf classes.jar open.java close.java"
Does anyone have a good model I can look at that can implement a dos command?

Maybe you can refer to this resource , I can not remember the Class, It seems like this Runtime.getRuntime().exec() ?? It can execute your command.

Similar Messages

  • Running a dos command from a java application

    hello,
    I'm trying to execute a batch file from a java application. I tried with:
    try
    Process proc=Runtime.getRuntime().exec("fop -fo "+iXmlFoFile+" -
    svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                               the Xml FO file into Svg file: "+e);}
    and with:
    try
    Process proc=Runtime.getRuntime().exec("cmd ./c fop
    -fo "+iXmlFoFile+" -svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                the Xml FO file into Svg file: "+e);}
    but i have a IOException: CreateProcess: .... error=2
    When I try these line to launch a .exe file it works but not with a .bat file.
    I also tried:
    String execstr = "fop -fo "+iXmlFoFile+" -svg "+SvgFileName;
    String [] commandArray = { execstr };
    try {
    Runtime.getRuntime().exec(commandArray);
    } // end try
    catch ( Exception e ) {
    System.out.println( e.getMessage() );
    e.printStackTrace();
    }// end catch
    but i got the same exception in java.lang.Win32Process.create
    What did i do wrong?

    Your execution string is a bit more that I want to figure out, but here are a couple ideas:
    Is the working directory of any importance? If so you'll need to set that when you do your exec()
    I think I remember reading something about batch files that couldn't be kicked off via this method. Perhaps you need to execute the string "start mybatchfile.bat". Seems like you need to do something like that to get a command interpreter to run your batch file.

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

  • Running a windows command line in java?

    Hi guys.
    I wonder if there's a way to run windows (dos) commands from within java. the code goes like:
    if (setting == true) {
    run dos command "ECHO Command is activated and running."
    please reply if you are able to help out. thanks a lot
    - n3phi|im`

    note that in some cases you can use a normal
    Runtime.exec ("program arg1 arg2");
    but in some cases the commands are built into the shell, so you have to do
    Runtime.exec ("command.com /c copy myfile here");
    "copy" is one of them, and "echo" is probably one too. The latter should work for all programs and commands, but might involve some overhead as a new instance of 'command' is created and destroyed for every command.

  • Is it possible to run a command prompt(or DOS Command) through flash and run a Activex(.OCX) file from flash

    Hi all
        Is it possible to run a command prompt(or DOS Command) through flash.If it possible please guide me to do that throug AS 3.0.
       and
    Is it Possible to run a activex (.OCX) file from flash. If it is so please guide me the way to do it
    Thanks and Advance
    Sankar.M.S

    Or create a desktop shortcut (in Windows) or an application launcher ( in Linux GUI).

  • 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

  • Execute dos commands through java

    Hi,
    Im trying to execute dos commands through java like
              try {
                   java.lang.Runtime.getRuntime().exec("cmd /c cls");
              }catch(IOException e){
                   System.out.println(e.getMessage());
              }Not sure if its possible? however
    open notepad would work
              try {
                   java.lang.Runtime.getRuntime().exec("notepad");
              }catch(IOException e){
                   System.out.println(e.getMessage());
              }Im trying to execute a cls commands to clear screen but without luck.

    The question is, which shell do you want to clear?
    I don't really know, but it could be that Runtime.exec executes its command in a new shell window...

  • How to call dos commands through HTMLDB buttons

    HI,
    How do i call DOS commands through HTMLDB buttons, or on any process?
    can anyone help me on this?
    THANKS!
    BROKEN

    This article explains how to execute shell commands from whitin pl/sql using java (in the database).
    http://www.oracle-base.com/articles/8i/ShellCommandsFromPLSQL.php
    It is for Oracle8i but should still work. This still looks like a good way to go.
    ~Dietmar.

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

  • How to execute Dos Command 'Pause' from Java ?

    How to execute Dos Command 'Pause' from Java ?
    I have read the article in javaworld for Runtime.exec() anomalies.
    Can someone please give an insight on this?

    Thanks Buddy!
    That was very useful. Even though its a simple
    solution, I never thought about that.Bullshit! Reread reply #7 of http://forum.java.sun.com/thread.jspa?threadID=780193

  • How to run a openssl command from a java program

    Hi All
    Please suggest on how to run a openssl command from a java program.
    I am using this
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
    This is suppose to take test.der as input and create result.pem.
    There are no errors but the file result.pem isnt created.
    Thanks in Advance

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • How to run a DOS command from an Oracle form.

    How can I run a DOS command from an Oracle form (i.e. open the calculator located at c:\windows\system32\calc.exe)?

    first of all get the environment variable for the c:\windows\system32 direcotry for any of the windows
    you can use get variable from the ora env package
    now cancat the system32 variable with the calc.exe string
    now pass the string with host command as parameters
    this process will work for all type of windows.

  • 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

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

  • Running a perl shell command through a java program on linux platform

    i'm trying to execute the following command in a java program "perl xxx.pl" using the runtime.getruntime method
    here is the piece of code
    String[] cmd={"perl","-c","AraMorph.pl",""};
    Process p = Runtime.getRuntime().exec(cmd,null,new File("/home/ahmed/buckwalter_morphan_1/data"));
    p.waitFor();
    BufferedReader in=new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line=in.readLine())!=null)
    System.out.println(line);
    but it doesn't output anything even if i tried to print the output to a file
    i'm trying to execute this program on linux platform but its working properly on a windows platform
    thx
    raar

    String[] cmd={"perl","AraMorph.pl"," </home/ahmed/in.txt"," >/home/ahmed/ast.txt"};
    Process p = Runtime.getRuntime().exec(cmd,null,new File("/home/ahmed/buckwalter_morphan_1/data"));
    BufferedReader in=new BufferedReader(new InputStreamReader(p.getErrorStream()));
    String line;
    while ((line=in.readLine())!=null)
    System.out.println(line);
    p.waitFor();
    String str2=p.getInputStream().toString();
    System.out.println("==================================="+str2);
    and it still outputs nothing but goes in something like infinite loop or as assumed in the article u suggested a deadlock but even all solutions to all pitfalls didn't succeed

Maybe you are looking for