Results 1 to 4 of 4
- 05-01-2009, 11:18 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 8
- Rep Power
- 0
how to get the values from command prompt
hi all i have code which executes the .bat file from command prompt
import java.io.*;
class test{
public static void main(String arg[]){
try{
String command = "cmd /C start C:/test.bat ";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
}catch (IOException e) {
e.printStackTrace();
}
}
}
here is the query
how can i display the results which are executed by test.bat through java application.
- 05-01-2009, 05:56 PM #2
take a look at the Process API doc.
Java Code:String command = "cmd /c @echo Hello World!"; ... Scanner scan = new Scanner(pr.getInputStream()); ...
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 05-02-2009, 07:28 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 8
- Rep Power
- 0
here is mycode
import java.io.*;
class parsingapplication1
{
public static void main(String args[]) throws IOException
{
Process process = Runtime.getRuntime().exec( "cmd /C start C:/test.bat" );
byte[] readBuffer = new byte[1024]; //created object for the byte class
StringBuilder stderrBuffer= new StringBuilder(); //created object for StringBuilder
InputStream errorIs = process.getErrorStream(); //to display errors
int bytesRead = errorIs.read( readBuffer );
while( bytesRead >= 0 )
{
stderrBuffer.append( new String( readBuffer, 0, bytesRead ) );
bytesRead = errorIs.read( readBuffer );
}
// do something with stderrBuffer
StringBuilder stdoutBuffer = new StringBuilder();
InputStream inputIs = process.getInputStream();
bytesRead = inputIs.read( readBuffer );
while( bytesRead >= 0 )
{
stdoutBuffer .append( new String( readBuffer, 0, bytesRead ) );
bytesRead = inputIs.read( readBuffer );
}
}
please check it once
- 05-02-2009, 08:32 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you get any error message there in the above code. What you exactly going to do?
And also, seems to me you've misses the last closing bracts in the class. ;)
Similar Threads
-
Creating a Jar File Using Command Prompt
By hitmen in forum New To JavaReplies: 14Last Post: 08-27-2011, 12:05 PM -
Creating a Jar File Using Command Prompt
By hitmen in forum New To JavaReplies: 6Last Post: 03-18-2009, 04:37 PM -
Running applet from command prompt
By niteshwar.bhardwaj in forum Java 2DReplies: 1Last Post: 03-12-2009, 08:10 AM -
help me!!!! about command prompt..
By kureikougaiji in forum New To JavaReplies: 2Last Post: 11-13-2008, 06:15 PM -
Problem during executing Command Prompt
By keshari in forum Advanced JavaReplies: 4Last Post: 06-05-2008, 04:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks