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
JaimeThanks 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 suggestionsI'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,
HimanshuHi,
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
sandyI 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....
NateFirst 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
-
Hi friends, I have imported the best practices package on my portal. created the queries in BW and assigned the roles user mapping etc all done. When I open the executive cockpit overview all I get is the standard adhoc query screen without any data.
-
I am a UK customer, and last night I purchased Top Gear India Special on my iPad, and I chose to download the 1080p version. I'm just wondering why iTunes hasn't downloaded an SD version as well as the HD version, like it always has done previously?
-
My mountain lion OS hangs like windows does and sumtimes have visual glitches like the drop down menu's are half visible. Sometimes it slows down at every point. And its just 2 months old. Please help.
-
Nothing happens when I print.
Nothing happens when I try to print if I'm using Photoshop, or Acrobat. Sometimes nothing happens in InDesign, but it worked fine with illustrator. I haven't had any printing problems with other non-adobe applications. Also Photoshop can find my scan
-
Where to get Application Development 11.1.1.4 CD
With the release of JDev 11.1.1.4 and WLS 10.3.4 - where do we download the latest application development runtime (in order to install the JRF template in WLS)? The Fusion Middleware Download Page (where we can get 11.1.1.2 and 11.1.1.3 versions of