Running command prompt commands in java
I can use:
Process j = Runtime.getRuntime().exec("command";
BufferedReader stdInput = new BufferedReader(new InputStreamReader(j.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(j.getErrorStream()));
to run commands in the command line buf if i make another process..the command will not run...any ideas?
ProcessBuilder can simplify things:
redirectErrorStream
<quote>
If this property is true, then any error output generated by subprocesses subsequently started by this object's start() method will be merged with the standard output, so that both can be read using the Process.getInputStream() method. This makes it easier to correlate error messages with the corresponding output.
</quote>
Similar Messages
-
How java runs in command prompt and why java runs on it
how java runs in command prompt and why java runs on it
command prompt was used before the development of IDEs like RAD,eclipse etc.
its still used for better understanding of the compilation and errors.
type the java file and save the file(source file) in the bin folder of ur jdk environment with extension .java. the source file must be the one that has the main method declared.
in the cmd prompt screen , set the path of bin folder.
eg:C:/program files/jdk(some version)/bin/...
for compilation,type:
javac (source file_name).java and press enter
for running the file:
java source file_name -
How to execute a Command Prompt command from J2SE code executing on Windows
How to execute a Command Prompt command from J2SE code executing on Windows??
Please help me[http://java.sun.com/docs/books/tutorial/getStarted/]
~ -
How to run a command prompt " command " through java code
hi all,
There is a command
"java -jar selenium-server.jar -interactive"
which i am running through command prompt after going to D:\MyFolder\Examples .
i want to execute this command using java code .please helpThis has already been answered in your other two threads on this topic - http://forum.java.sun.com/thread.jspa?threadID=5221221&messageID=9898287#9898287 and http://forum.java.sun.com/thread.jspa?threadID=5221223&messageID=9898290#9898290.
For some reason you don't want to read the reference that tells you exactly how to do what you want and how to avoid the pitfalls - http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html . -
Runtime.exec() I need to run a command prompt command from java.
the code i have that doesn't seem to work is:
String driveloc = System.getProperty("user.dir").substring( 0, 1 );
String path = jTextFieldPath.getText();
String path2 = jTextFieldPath.getText().substring(0, jTextFieldPath.getText().length()-3) + "lst";
String[] cmd = { "cmd.exe", "/" + driveloc, "ASMtools\\AS11 " + path + " -L >" + path2};
txt_mf.append( cmd[3] );
try {
Process np = Runtime.getRuntime().exec( cmd );
catch( java.io.IOException ioe) {
//error
}jTextFieldPath.getText() contains the path of the file saved by my program.
the line of code i am trying to run is:
AS11 FILE1 -L FILE2this line compiles the asm file and converts it to a lst creating an s19 file in the process. AS11 is an exe that aids the command prompt much like javac.
If you could help me figure this out it would be great.
Thanks in advance,
-JukeString driveloc =
System.getProperty("user.dir").substring( 0, 1 );
String[] cmd = { "cmd.exe", "/" + driveloc,
"ASMtools\\AS11 " + path + " -L >" + path2};Are you sure you want to invoke cmd.exe with the switch /c or /d or whatever depending on System.getProperty("user.dir") ?
Starts a new instance of the Windows 2000 command interpreter
CMD [A | /U] [Q] [D] [E:ON | /E:OFF] [F:ON | /F:OFF] [V:ON | /V:OFF]
[[S] [C | /K] string]
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
/D Disable execution of AutoRun commands from registry (see below)
/A Causes the output of internal commands to a pipe or file to be ANSI
/U Causes the output of internal commands to a pipe or file to be
Unicode
/T:fg Sets the foreground/background colors (see COLOR /? for more info)
/E:ON Enable command extensions (see below)
/E:OFF Disable command extensions (see below)
/F:ON Enable file and directory name completion characters (see below)
/F:OFF Disable file and directory name completion characters (see below)
/V:ON Enable delayed environment variable expansion using c as the
delimiter. For example, /V:ON would allow !var! to expand the
variable var at execution time. The var syntax expands variables
at input time, which is quite a different thing when inside of a FOR
loop.
/V:OFF Disable delayed environment expansion. -
Running command prompt externally from Java
Hi,
Does anyone know how to make a Java program that opens up the command prompt and runs certain commands? Thanks,
AdamRead this before you use it:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -
How i can open a new command prompt from one java from
hi
can any one help me that how i can open a command prompt by using the java program file .
regards,
ukbasakhttp://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String)
and several overloads.
Also
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html -
How to pass Key Event from command prompt to the java application
If iam running a application that displays JFrame when i pressed CTR+C at the command prompt i.e console window please let me know how can it be passed to the JFrame ie application window
I doubt that you can pass Ctrl+C to the application since the application is terminated by this key combination.
You would try adding a WindowListener or may use a shutdown hook to capture the termination of the JVM. -
Invoking command prompt & executing a java class from one more java class
Hi,
I have a problem with my application. I need to develop an editor which compiles and interpretes java programmes. I am develoopping it in Java (Swing and pure Java). I have no problem in compiling a java programme from my editor. But while execuing if any body writes a programme which has console input the system hangs. I am using Runtime.exec() method to call command prompt of Win'2000. My editor is working fine for the programmes written without console input in my editor. I want the same type of input acceptance as JCreator / Vim editors accept.
How can i achieve this? Please give me some source code help for my requirement.When you create a Process object from executing a command you can grab it's input and output streams. Using these, and a text area, you can create a "virtual terminal" for your user to work with their console programs. The rest is just details :)
-
I know that while I use the command prompt in windows to execute java application, I cannot use the other windows commands such as
ipconfig,
telnet...
etc
Is there anyway where I can use the java commands (javac, java) AND the other regular commands??The problem is happening because the PATH variable
settings is not proper.
Go to the environment variables in your machine and
append the following to the PATH environment
variable
%SystemRoot%\system32;%SystemRoot%;Save and then open a new command window and try.Yep, you were right.
I did that to the user's path and it worked after I appended it. It works for both now,
thanks. -
Problem in executing command prompt commands through application
Hi,
I am facing issue in executing commands through VC++ application.
My application is a dialog based MFC application in VS2008.
I want to execute below commands programmatically.
devenv D:\TestApp\TestApp.sln /rebuild release
devenv D:\TestApp\TestApp.sln /rebuild debug
But I am not able to set the current directory path as "D:\TestApp\" programatically.
Through which API I can execute multiple commands on command prompt programmatically same as we do manually on cmd.
Please Help.
Thanks in Advance.
Thanks & Regards, Mayank AgarwalI want to execute below commands programmatically.
devenv D:\TestApp\TestApp.sln /rebuild release
devenv D:\TestApp\TestApp.sln /rebuild debug
But I am not able to set the current directory path as "D:\TestApp\" programatically.
Through which API I can execute multiple commands on command prompt programmatically same as we do manually on cmd.
Why can you "not able to set the current directory path as "D:\TestApp\" programatically"? Are you forgetting to escape the backslashes?
Why to you need to set the current directory anyway?
What is the problem with executing multiple commands?
As to your basic goal, have you looked at
system()
ShellExecute()
ShelExecuteEx()
CreateProcess()
? Perhaps you should show us what you have tried.
David Wilkinson | Visual C++ MVP -
This is a stoopid question and I've searched the forums, but what is the command in DOS prompt to view your classpath.
When I run java -classpath it gives me all the various options e.g.
java -cp -classpath
but non of these work? whats the craic?
M.What do you mean by "none of these work"?
Suppose that you have a file HelloWorld.class in the directory C:\MyClasses. If you type:
java -classpath C:\MyClasses HelloWorld
it should run your program without problems.
Are you getting an error message? What's the error message?
Jesper -
System 32 command prompt commands to factory reset hp notebook 2000 laptop
Need to factory reset notebook from command prompt
Normally tapping the F11 key immediately after powering on will boot into Recovery Manager.
******Clicking the Thumbs-Up button is a way to say -Thanks!.******
**Click Accept as Solution on a Reply that solves your issue to help others** -
Set java path to run jar in command prompt
i have installled only jre.. i dont have jdk..
Is it possible to run jar command in command prompt.
if possible please give me jar command...
thanks in advancei have installled only jre.. i dont have jdk..ok
Is it possible to run jar command in command prompt.Please, read java tutorial before posting such question
if possible please give me jar command...Please, read java tutorial before posting such question -
Run class in jar file using command prompt
Hi,
I have created a jar file OSTBTLDataTransfer.jar using eclipse and tried to run a class Person in the package com.aqa.details using the command prompt like this
java -classpath com.aqa.details.Person
but this complained about a jar file dependency and i have set it to the classpath like this:
set CLASSPATH=C:\jarup\abc\ibatis-2.3.4.726.jar
but it couldn't find the dependency when i tried to run again.
please let me know your suggestions
Thanks,
KCjava -classpath OSTBTLDataTransfer.jar com.aqa.details.Person
or if you have an appropriate manifest in the jar simply
java -jar OSTBTLDataTransfer.jar
Maybe you are looking for
-
Payment term & Cash discount relation
Hi Group, I want to maintain the relation ship between cash discount condition type and payment term. I dont want to use SKTO or SKTV because those are applicable for all the material that are there in the sale order. My cash discount requirement are
-
I just upgraded my regular DSLR to a full frame Nikon D600. I've shot in RAW for a long time and never had any trouble with Elements 9 opening my RAW files via Camera Raw. I can't find which version of Camera Raw I have, but I know it does not reco
-
IPhone4S: tried to update to iOS6 and now will only show "connect to iTunes" screen
I've got an iPhone4S and tried to update to iOS6 via iTunes. While installing, a message came up on my computer saying that "iOS6 could not be installed due to an unknown reason" (I'm paraphrasing b/c I didn't write it down, figuring that I could ju
-
My Zen micro 5gig freezes at the loading screen. It loads the first screen than swaps to a screen that says "creative" and gets no further. i can get to the recovery screen, but when i try to reload the firmware, it starts erasing and just freezes ag
-
Unusual Apache error_log entries
My Apache error_log (and my wife's) are full of these: [Mon Feb 04 13:19:31 2013] [error] [client 127.0.0.1] File does not exist: /Library/WebServer/Documents/crls [Mon Feb 04 13:19:31 2013] [error] [client 127.0.0.1] File does not exist: /Library/We