Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JAVA to DOS

Status
Not open for further replies.

FurqanAhmed

Programmer
Oct 1, 2001
87
PK
I was wondering how could i pass commands to the DOS command line through my JAVA program. e.g

I want to check whether there is a directory "xyz" on c:. but i dont want to do it by using JAVA but rather pass commands to the DOS command line thorough my JAVA program.

I would really appreciate it.
 
there is an exec() method somewhere, although I honestly can't remember where.. however, I would urge strongly against using this. One of the strong points of java is its cross-platform capability; executing a &quot;dir&quot; command would be in direct conflict with that.<br><br>Also, I'm not understanding why you wouldn't want to use Java to see if there is an &quot;xyz&quot; directory? <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
Process p;
Runtime r=Runtime.getRuntime();
p=r.exec(&quot;dir c:\xyz&quot;);
InputStream is=p.getInputStream();
byte[] b=new byte[2000];//make big enough
int i;
while ((i=in.read(b))!=-1);
String s = new String(b);
if(s.indexOf(&quot;File Not Found&quot;)==-1)
{
//file exists
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top