Dos cli in java

Greetings,
I am told that I have a tendency to provide too much information, so I will try not to. I have search these forums and the internet in general for what I am looking for and have not found it. I am looking for a dos cli in a java application.This will be part of a larger program. I do not want to emulate dos, nor do I want java to run some commands for me, nor do I want to open the program written in C++ that is distributed with widows (cmd.exe). I want to have the cli in java as an object. It should be able to run any thing that a regular command prompt is able to. Has anyone made or seen some code like this? Is it possible? If possible could someone provide some source code that would atleast get me started?

Such a thing wouldn't be easy to write. For example when the user types the command "cd hamburger" into your shell emulator, that has to change the current working directory in the emulator. Likewise when the user types the command "set hamburger=free" into your shell emulator, that has to update the list of environment variables which your emulator is keeping track of. Which it will have initialized by copying the list of environment variables from the environment when it started up.
All of that is pretty trivial. But when the user types the name of an executable, and you track that executable down using your emulator's version of the PATH environment variable, you have to make sure that when you run it, it runs in an environment containing your shell's version of the environment variables. And you're going to have to have a batch-file interpreter which works the same as the existing Windows one. Note that you can't just run a batch file in a different process because a batch file can change the environment variables of the CLI it runs in (i.e. in your emulator).
I'm sure the list goes on. And as already said, why would anybody go to all this effort just to duplicate the Windows shell? Okay, I can see somebody doing it for fun, but would they get all of the gotchas covered?

Similar Messages

  • How to execute dos command in Java program?

    In Perl, it has System(command) to call dos command.
    Does java have this thing?
    or any other way to execute dos command in java program?
    Because i must call javacto compile a file when the user inputed a java file name.

    Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
    exec(String command) that will execute that command in a dos shell.
    Regards,
    Gerrit.

  • How to execute DOS command in Java?

    I want to execute a dos command in Java,such as execute test.bat command? How to realize it?
    Thanks in advance!

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    I found this article really useful in solving this. Hope it helps.
    Cheers,
    John

  • Running Dos command in Java

    hey, Just wondering can anyone help me get started, i pretty new to java and wanted to run the date command in Dos from a java application. If i could just know where to begin or even if this is possible, it would be much appreciated!!

    If you're using Runtime.exec() you need to read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    If you're new to java it might be a bit heavy, but definitely add it to your "Favourites" for later!

  • How to run DOS command in Java environment?

    Can i run DOS command in Java environment?
    I did like this:
    Runtime r = Runtime.getRuntime();
    r.exec("cmd.exe");
    r.exec("set classpath=%CLASSPATH%;.\\tmp")
    but failed.
    However if I run the java command, it runs successfully.
    r.exec("javac Test.java");
    r.exec("java Test");
    how should I do so that i can run the DOS commands metioned above in Java Environment?
    thanks a lot.

    Have a look at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    This may help. I wonder if this is ok ?
    Runtime r= Runtime.getRuntime();
    r.exec("cmd.exe /C set classpath=%CLASSPATH%;.\\tmp\"");

  • Run dos command from java

    May I ask how I should write if I want to execute a dos command in java? The command is :
    "C:\Program Files\Real\realproducer\rmeditor -i abc.rm -d abc.txt". Should I use array?
    Thanks!

    why an array ?
    String command = "C:\\Program Files\\Real\\realproducer\\rmeditor -i abc.rm -d abc.txt";
    Process p = Runtime.getRuntime().exec( command );what about the seach function on the left side ? ;-)
    tobias

  • Dos command from java

    hi all
    how do i run dos commands from java??????????

    Using Runtime#exec().
    Also see http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html

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

  • 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

  • Dos command in java

    Hi
    I have used google to get an answer for this.
    This is the command i have used to run some dos commands in java
    Unfortunately it doesn't throws any exceptions but still the directory and the file news.txt is not created.
    Process t=objrun.exec("command.com /c dir > c:/news.txt");
    Process p=objrun.exec("command.com /c mkdir c:/Prabhath");
    Please help me....am using windows xp OS.

    Note that the java.util.File has the following methods that might do the job :public File[] listFiles()
    public boolean mkdirs()
    public boolean createNewFile()

  • How to invoke dos shell from java program

    Hi,
    I'm not able to invoke dos shell from java.
    Can any one help me in this issue.
    I'm providing the source code below:
    try{
    Runtime.getRuntime().exec("cmd.exe")
    catch(IOException e) {
    System.out.println(e.getStackTrace());
    Thanks

    Does it throw a different exception?
    Or does it just do nothing at all?
    It does nothing at all[/b
    Is this a standalone Java app?
    Or a Java Applet running via a webbrowser? [b]It's a standalone application

  • Clearing the DOS Window in Java

    hi
    I want to clear the dos screen using java.
    I saw 2 solutions on the net(given below) , but both did not work. Can someone advise how I can go about doing this ? I'm
    working on Windows2000.
    Thanks in advance.
    Seema
    1. char esc = 27; // ESC code
    String clear = esc + "[2J" // note case
    System.out.print(clear); // Dos screen should be cleared
    2. Runtime.getRuntime().exec( "cmd.exe /c cls" ) ;

    The escape code approach would only work on DOS windows that are processing ANSI escape sequences. This is something people used to enable all the time back in the pre-Windows days, since it was the only way to do things like clearing screens, setting colours, drawing menus out of text characters, etc. Ansi.sys still exists, at least on Win98 (not sure about NT, 2000, etc.). If you troll through the Microsoft web site or hunt down old books on DOS, you'll be able to find out how to set it up and use it.

  • Invoking dos commands from java

    hi all,
    I just want to invoke dos prompt from java.I know it can be done using "Runtime.getRuntime()" command.But when i try to create a directory inside another directory,how can i specify the path of the destination directory.i googled as well as tried different things.But i failed to make it up.Please help me solve this problem.
    thanks in advance
    Regards

    Hai,
    Thanks for your respond.
    If I give "cmd" command only, I am getting dos command window, but I didn't get the prompt like
    c: or d:
    How can I do it?
    Expecting more helps
    Joseph

  • EXECUTE DOS COMMANDS WITH JAVA

    I'm new to java and I want to execute dos commands by java
    can someone help me by by anyway?
    like tell me the packages or methods I need
    or give me links to sites?
    thanks

    No Arguments:
    try {
            // Execute a command without arguments
            String command = "ls";
            Process child = Runtime.getRuntime().exec(command);
            // Execute a command with an argument
            command = "ls /tmp";
            child = Runtime.getRuntime().exec(command);
        } catch (IOException e) {
        }With Arguments:
    try {
            // Execute a command with an argument that contains a space
            String[] commands = new String[]{"grep", "hello world", "/tmp/f.txt"};
            commands = new String[]{"grep", "hello world", "c:\\Documents and Settings\\f.txt"};
            Process child = Runtime.getRuntime().exec(commands);
        } catch (IOException e) {
        }

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

Maybe you are looking for

  • 64-Bit OS' no longer work on GT780DXR

    Hi there, Hopefully someone can help point me toward what might be going on here; basically the other day when turning my laptop on, it made it to the Windows 7 loading screen (with the rotating coloured balls), before suddenly crashing out and BSOD'

  • How Do I Sort a Group of Photos on the Same Page with the same Keyword Tag?

    I want to group similar photos on the same page with the same keyword tag.  I have tried dragging and dropping without any success.  Can anyone help?

  • Black flash in iMovie template

    I'm using iMovie 10.0.3.  I'm using the Retro template to make a video.  Near the end of the template, there is a millisecond of black video that I can't seem to get rid of.  It flashes between two "Title" clips.  I placed an iMovie "Transition" clip

  • Give each ship-to-party an internet user

    We have set up the Web shop for our customer using CRM Internet sales. Some of our customers have different ship-to parties,and we want give each ship-to-party an Internet User so that he can process order in the B2B shop. For example,Customer 110000

  • Correct confirmed account doesn't appear in service request

    Hi guys, let me brief my requirement: In IC webclient the service request is picking just previously cancelled conformed account as activity partner but not the current confirmed account. Th process to create the issue : Go to Account Identification