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

  • Database Error during installation of SAP NetWeaver 7.01 ABAP Trial Version

    Hi All, I was installing the SAP NetWeaver 7.01 ABAP Trial Version but during the installation i got some MaxDB error. Log.txt (Apr 28, 2010 10:13:41 PM), Install, com.sap.installshield.maxdb.maxdb_call_sdbinst, err, An error occurred and product ins

  • LAYOUT FOR FBL1N

    HI EXPERTS ! The transaction code for the report we generate is FBL1N - vendor ledger. we require the vendor's bank detail in this report at the header i.e. vendor bank name , account no..(change layout of report for output ) this detail can be seen

  • How can I copy and export a speaker track between project file?

    Hi, I am using Premiere Elements 12. I need to copy a speaker track (nothing else) in one project file and paste it into a new track in another project file. I can mark and copy the track but then it is IMPOSSIBLE to paste it. I have no such option -

  • Convert from feet to inches?

    Can numbers convert imported data from feet notation (i.e. 3' 6 1/2") to decimal inches (i.e. 42.5)? I'd like to be able to import rough opening dimensions from my internal CAD (Vectorworks 2008) spreadsheet to generate cut lists with numbers. I can

  • ADF graph refresh

    Hi, I am new to ADF and while learning, I am stuck in a problem and couldn't find a solution since long. I am explaining my demo project scenario as below , sorry for making it long ..................... I have two java class, ClassID that returns ID