Tuesday, March 31, 2009
Dashed line drawing in java graphics.
Wednesday, March 18, 2009
Closing command prompt from JAVA
Many times developer ask question how to close command prompt after
launching the application?
or
How to exit from batch file after execution.
Here is all possible ways to do so.
1. Use javaw.exe for launching your application and exit.
2. Create an executable jar file so that just double clicks for launch.
3. Create exe from jar files.
If you want to exit from command prompt after calling your exe file.
Then apply the same concept which we are using for tracing output
from exe.(see previous post)
Technique:-
1. You have to insert a line on your code which print "Loaded" on output.
2. Crate a jar file then exe from jar file.
3. Again make a java file for launching your exe file.
4. Get the InputStreamReader from your process.
5. Check for string "Loaded" on output.
6. If you get "Loaded" then exit.
See the full source code.
/* Program for closing a command prompt from a executable
call exe from a batch file like...
java Loader
Tracing output from Exe in JAVA
Monday, March 9, 2009
Reading command Line Input in JAVA
Reading Command Promt Output from JAVA
Hello Friends,
/*
* Program for reading a command prompt output from java
* Copyright 2009 @ yuvadeveloper
* Code By:- Prashant Chandrakar
*
*/
import java.io.*;
public class cmdReader
{
public static void main(String arg[])
{
new test().setup();
}
void setup()
{
System.out.println("Testing getVolName");
////drive which name to be read
String path = "D:";
System.out.println("Volume name for " + path + " is: " + "'" + getDiskVolumeName(path) + "'");
}
public static String getDiskVolumeName(String path)
{
String volname = "Unknown";
String check = "Volume in drive " + path.charAt(0) + " is ";
try
{
//creating a process object and calling a cmd.exe with /c dir option
Process p = Runtime.getRuntime().exec("cmd /c dir " + path);
//getting input stream from a process
InputStreamReader is = new InputStreamReader(p.getInputStream());
//creating a buffered reader object for reading purpose
BufferedReader reader = new BufferedReader(is);
///reading a line
String line = reader.readLine();
while (line != null)
{
//getting substring for drive name
if (line.indexOf(check) != -1)
volname = line.substring(line.indexOf(check) + check.length());
line = reader.readLine();
}
}
catch (Exception e1)
{
System.out.println("Failure: " + e1.toString());
}
return volname;
}
}
Here below i am pointed the read text.