Manipulating Windows command prompt through Java

I am wondering if there is any way to manipulate simple Windows command prompt commands like color, cd, dir, cls through a java application. Any help or informative redirection would be much appreciated.

BinaryBurnout wrote:
I am wondering if there is any way to manipulate simple Windows command prompt commands like color, cd, dir, cls through a java application. Any help or informative redirection would be much appreciated.Realize that the Windows command prompt is an application (cmd.exe), and those commands are specific to that application.

Similar Messages

  • How to get no. of rows of Windows Command Prompt in java

    hi all,
    can anybody tell me that is there any java utility avalilable throght I can find the how many rows avalilbe on currently executing command prompt, and also how can i clear the content of command prompt (result of 'cls' command).
    Currently execting command prompt means from where I have run my java program.
    any reference is also welcome.
    thanks in advance.

    Clearing the screen is trivial, as long as you're OK with making your program specific to Windows only (i.e. you never hope to run it on any other OS ever):
    Runtime.getRuntime().exec("cmd /c cls");As to figuring out how many lines your command window's screen buffer has - good luck with that. I'm not familiar enough with the Win32 API to get this info, but you'll have to figure out what that is, and call it via JNI.

  • Using command prompt through java, help please!

    Hi,
    What I am trying to do is find all the processes running onthe computer using java. Normally, I would do this (without java) by opening a command prompt window, typing in tasklist and see all the running processes. I have tried to to do the same thing using java, but so far have been unsucsessful. Here is my code:
    import java.io.*;
    public class Main {
            static DataOutputStream output;
            static DataInputStream input;
            static String app="cmd.exe";
            static String command="tasklist";
            static String message="";
            public static void main(String args[])throws Exception{
            Process process = Runtime.getRuntime().exec(app);
            output=new DataOutputStream(process.getOutputStream());
            input=new DataInputStream(process.getInputStream());
            output.write(command.getBytes());
            byte[] b=new byte[input.available()];
            input.readFully(b);
            message=new String(b);
            System.out.println("Message: "+message);
            System.out.println(!message.equals(""));
            System.out.println(message!=null);
            System.out.println("Finished Program");
    }And this program prints the output (with no exceptions):
    Message:
    false
    true
    Finished Program
    I appreciate any help in fixing my program...

    DevRocks_Java wrote:
    static String app="cmd.exe";
    static String command="tasklist";
    Process process = Runtime.getRuntime().exec(app);
    output=new DataOutputStream(process.getOutputStream());
    input=new DataInputStream(process.getInputStream());What do you expect it to do? You are only telling it to open a console window, nothing more.
    if you can type tasklist at the run option, then you should be able to just substitute command in for app in your exec.

  • Using Java in windows command prompt

    Hi,
    I don't know if I have been searching correctly, but I haven't found a solution to my problem through common search engines.
    I'm programming in java using vim (accessed through windows command prompt), and I've created classes, everything compiles fine.
    However, I wanted to test my classes my creating instances of them (i.e. objects) through the same windows command line (command prompt). I know you can achieve this by using interaction panes through third party programs such as Dr.Java and eclipse, but I was wondering if this can be done using the command line.
    Thanks
    Jaime

    Thanks Paulcw for your quick reply! :D
    I'm guessing I didn't word my question properly.
    Neither of my classes have a main method in them, so when I am trying to create instances (objects) of them, I would like to as if my command line was the main.
    For example:
    Class1 c = new Class1(parameters);
    c.moveRight();
    etc.
    I'd like to be able to use my classes methods from the command line, I think what I'm looking for is a batch, but I'm not sure.
    Thanks again,
    Jaime

  • Java Code Compilation in Windows Command Prompt

    Hi Everyone,
    I have been programming in java for quite some time now using an IDE (eclipse). I downloaded the following java file from:
    http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/JpegImagesToMovie.html#requirements
    and have downloaded the required JMF. The problem is that I want to compile and run this code in Windows Command Prompt; however, I keep receiving errors upon compilation because I do not know how to make jmf.jar be recognized as a library.
    Thx.

    javac -cp jmf.jar;otherJars file1.java file2.java file3.java...
    Run java and javac from the command line for an explanation of their options.
    Edited by: nclow on Jul 24, 2008 1:43 PM

  • TDMS Defragment​-Through Windows Command Prompt

    Dear All,
    we need to Defragment the TDMS file  by TDMS Defragment.VI  via Windows Command Prompt.
    Work flow will be as below
    1.An Application wil be created to defragment using TDMS Defragment.VI
    2. When user stop Main Application (App 1) which records data for long time in tdms  ,the Main application (App 1)  will call defragmenting Application (App 2) via cmd and should get the file path and start defragmentation and it should pop a message defragmentation completed. and dont want Main Application  (App 1)  to do anything apart from triggering tdms defragmentation.
    Reason is We dont want the Main Application (App 1)  to wait for Long time till defragmentation and Since we need to use the Main Application (App 1)  for other testing.
    So we decided to do this defragmentationin in some other way  and display the completion message to user
    please provide suggestions 

    I'd also recommend doing this in one application.  If you truely want to do it from a command line you can.  LabVIEW built EXEs can support command line switches if you enable it in the build specificaitons.  If you do this you'll probably want to support multiple instances, and code it so that it will exit once the conversion is done.  But again you can get more information from the result of the defrag (like error) if you do it in the same application.
    Taki1999 wrote:
    EDIT: Asynchronously is difficult to spell
    Totally agree and some spell checks claim it isn't a word.  Same with programmatically.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • How to execute a scenario from Windows command prompt

    Hi,
    I have a package which is executing fine from Designer. But the same scenario if I am trying to execute from windows command prompt, then it is giving error.
    The package is getting a refresh variable, passing to interface which is creating a file from table, this file is then getting FTP'ed to another server.
    I am executing following command -
    startscen OB_TAB_TO_FILE_PKG 001 ODICTX "-v=2"
    The error is -
    A JDK is required to execute Web Services with OracleDI. You are currently using
    a JRE.
    OracleDI: Starting scenario OB_TAB_TO_FILE_PKG 001 in context ODICTX ...
    java.sql.SQLException: socket creation error
    at org.hsqldb.jdbc.jdbcUtil.sqlException(jdbcUtil.java:67)
    at org.hsqldb.jdbc.jdbcConnection.<init>(jdbcConnection.java:2451)
    at org.hsqldb.jdbcDriver.getConnection(jdbcDriver.java:188)
    at org.hsqldb.jdbcDriver.connect(jdbcDriver.java:166)
    at com.sunopsis.sql.SnpsConnection.u(SnpsConnection.java)
    at com.sunopsis.sql.SnpsConnection.c(SnpsConnection.java)
    at com.sunopsis.sql.i.run(i.java)
    DwgJv.main: Exit. Return code:-1
    Please let me know where I am going anything wrong.
    Thanks,
    Himanshu

    Hi,
    you need to make the necessary changes to the %odi%\bin\odiparams.bat config file, under the "Repository Connection Information" section so that startscen knows how to extract metadata from your repository.
    You apparently have left the default settings to the Hypersonic demo repository. Is that the technology your repository is hosted on?

  • Creating windows user account through java

    Hi,
    Is it possible to manage(create/edit/delete) windows user account through java.
    Where in the java program is used to create windows accouunt on the same machine.....
    I did that with the net command and running the net command in java.... is there any better approch to this problem
    Regds
    sandy

    I have heard something about the JDesktop, will it be
    possible if i use the JDesktop,How would I know, it's not a standard library. Go and have a look at it.

  • Unable to connect to database from windows command prompt

    Hi All,
    Im trying to connect to Oracle database from my windows command prompt, these are the steps I followed:
    1) cd C:\oracle\product\11.2.0\client_1\sqlplus
    2) sqlplus username\password@hostname:1521\service_name
    I do get the error ORA-06401: NETCMN: invalid driver designator
    I did try using the SQLPLUS \NOLOG
    Connect username\password@hostname:1521\service_name
    I still get the same error.
    I did manually type all the commands to make sure no additional charaters coming and etc...How shall I overcome this...

    user9103174 wrote:
    Hi All,
    Im trying to connect to Oracle database from my windows command prompt, these are the steps I followed:
    1) cd C:\oracle\product\11.2.0\client_1\sqlplus
    2) sqlplus username\password@hostname:1521\service_name
    I do get the error ORA-06401: NETCMN: invalid driver designator
    I did try using the SQLPLUS \NOLOG
    Connect username\password@hostname:1521\service_name
    I still get the same error.
    I did manually type all the commands to make sure no additional charaters coming and etc...How shall I overcome this...do you desire/plan on using EZCONNECT or tnsnames.ora entry?
    EZCONNECT sample is below
    sqlplus user1/pass1@'dbserver:1521/orcl_sid'

  • Log ConsoleHandler + Windows Command Prompt

    Having really strange problem:
    Program started from Windows Command Prompt.
    Logging with ConsoleHandler.
    If select something with "Edit->Mark" in this Command Prompt, process stop responding.
    Has anybody seen such behavior?

    Correction:
    Looks like anything writing to stdout/stderr hangs in Windows Command Prompt "mark" mode.
    Could not find anything about how it works.

  • Javac command in windows command prompt

    Hi, i would just like to know how i can enable the javac command in the command prompt of windows without being in the java/bin directory...i have tried env. variables and stuff but to no avail, however the java command work.
    Thanks Rudy
    ps does anyone know any good rmi tutorials which are easy to follow, thanks.

    Err, nm, just reread that.
    The environment Path is the way to go.
    Just add the bin directory to the end of the PATH in the advanced option of my computer. You may need to reboot.

  • Set Title of Windows Command Prompt Window

    I'm running a text-only Java application in a Windows XP Command Prompt window. Is there a way for my application to change the title of the window as it runs?

    GaryS wrote:
    I'm running a text-only Java application in a Windows XP Command Prompt window. Is there a way for my application to change the title of the window as it runs?no. command prompt actions in java are weak/nonexistent. probably due to the lack
    of cross platform similarities. you can always run your program using a batch file and
    set the title in there.

  • How to set values to unniverse prompts through java

    Hi
    I am using JAVA -BOSDK to access reports from infoview. I have a problem when any universe level prompt is present in the report. I am able to retrieve it through java when i say documentInstance.getPrompts() and when i set values to this prompt by Prompt.enterValues(String[] parameters) and then either save the report or saveAs another report , my new values dont get applied to the prompt. Only previous values get applied to the prompt. I checked doing prompt.getPreviousValues and prompt.getCurrentValues but when i save the doc then new values are not set.
    here is a part of code iam using: the filterlist contains the ConditionFilterDataItems objects which contain the operands,operator and queryObjectName .I have added multiple prompt.getPrevious and current values for debug purpose.
    private static void applyValuesToUniversePrompt( final DocumentInstance doc, final List filterList )
            final DataProviders dps = doc.getDataProviders() ;
            final DataProvider dataProvider = dps.getItem( 0 ) ;
            final Query query = dataProvider.getQuery() ;
            Prompts newPrompts = doc.getPrompts();
            Prompt newprompt = newPrompts.getItem( 0 );
            newprompt.getPreviousValues();
            newprompt.getCurrentValues();
            final ConditionContainer conditioncont = (OMConditionContainer) query.getCondition() ;
            ConditionFilterDataItem conditionFilterDataItem = null ;
            final Map promptMap = generateInstanceMap( doc ) ;
            //Prompt [] promptArr ;
            for( int i = 0 ; i < filterList.size() ; i++ )
                conditionFilterDataItem = (ConditionFilterDataItem) filterList.get( i ) ;
                final String [] operands = conditionFilterDataItem.getFilterOperand() ;
                PromptsImpl univPrompts = (PromptsImpl)doc.getPrompts();
                Prompt [] promptArr = new Prompt[univPrompts.getCount()];
                for(int k= 0;k< univPrompts.getCount();k++)
                     promptArr[k] =(Prompt) univPrompts.getItem( k );
                if(univPrompts.getCount()==0)
                    promptArr=null;
              if(promptArr!=null)
                for( int j = 0 ; j < promptArr.length ; j++ )
                    final Prompt prompt = promptArr [j] ;
                    final String promptName = prompt.getName() ;
                    final Prompt currentPrompt = (Prompt) promptMap.get( promptName ) ;
                    if( operands [j] != null )
                        currentPrompt.getPreviousValues();
                        currentPrompt.getCurrentValues();
                        currentPrompt.removeValues( currentPrompt.getPreviousValues() );
                        currentPrompt.enterValues( convertStringToArray( operands [j] ) ) ;
                        currentPrompt.getPreviousValues();
                        currentPrompt.getCurrentValues();
                        doc.setPrompts();
                        newPrompts = doc.getPrompts();
                        newprompt = newPrompts.getItem( 0 );
                        newprompt.getPreviousValues();
                        newprompt.getCurrentValues();
            //doc.setPrompts() ;
            doc.refresh();
            doc.save();
            newPrompts = doc.getPrompts();
            newprompt = newPrompts.getItem( 0 );
            newprompt.getPreviousValues();
            newprompt.getCurrentValues();
           // dataProvider.runQuery() ;
            doc.refresh();
            doc.saveAs( "universePrompt2",7148,null,null ) ;
             doc.closeDocument() ;
    private static Map generateInstanceMap( final DocumentInstance document )
            final Map promptMap = new HashMap() ;
            final Prompts prompts = document.getPrompts() ;
            int count ;
            if( prompts != null )
                count = prompts.getCount() ;
                for( int i = 0 ; i < count ; i++ )
                    final Prompt prompt = prompts.getItem( i ) ;
                    promptMap.put( prompt.getName(), prompt ) ;
            return promptMap ;

    Hi Shruti,
    Can U kindly refer this [thread|BusinessObjects Enterprise Java Software Development Kit (SDK) ??; and reply back.
    Would appreciate your efforts !!!

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

  • Trying to find a way to execute from command prompt using java....

    I want to find a way to execute a command from the command line using a java program this is my code:
    import java.io.*;
    public class SQLHopefully
         public static void main(String[] args)
              try{
              Runtime rt = Runtime.getRuntime();
              Process proc = rt.exec("cmd /k start cmd.exe");
              OutputStream out = proc.getOutputStream();
              System.out.println(out);
              out.write("test.txt".getBytes()); //I THOUGHT THIS WOULD WORK
              InputStream stdin = proc.getErrorStream();
              InputStreamReader isr = new InputStreamReader(stdin);
              BufferedReader br = new BufferedReader(isr);
              String line = null;
              while ( (line = br.readLine()) != null) {
              System.out.println(line);
              stdin = proc.getInputStream();
              isr = new InputStreamReader(stdin);
              br = new BufferedReader(isr);
              line = null;
              while ( (line = br.readLine()) != null) {
              System.out.println(line);
              int exitVal;
              try {
              exitVal = proc.waitFor();
              } catch (InterruptedException e) {
              throw new IOException(e.getMessage());
              if (exitVal != 0) {
              throw new IOException("Exit value was " + exitVal ");
              }catch(IOException e)
              {System.out.println("ummmmm");}
    I hope my code is readable. I am trying to get the command prompt that comes up from the Runtime.exec() to run a file called "test.txt" I know it would be easier to just do it by executing it from java but I want to see if it is possible this way. I thought the out.write would do the trick but I was wrong. Somebody help please....
    Nate

    First read this article:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Second, you should probably send the Enter key to the shell if you want anything to happen. (Not that I know whether it will work, but I do know it won't work if you don't press Enter.)

Maybe you are looking for