Open dos command prompt from java

T

Tomer Ben-David

Hi

Is there any way to open the dos command prompt from java (this black
dos window...)
I want to execute some dos command and to execute them using java code
that will run them inside that black dos window...

I know I can use...
Runtime.getRuntime().exec("run.bat", null);
and get a handle to its inputStream however this is not what I want
since I want to open that run.bat in the dos prompt ...
 
S

Steven J Sobol

Tomer Ben-David said:
Hi

Is there any way to open the dos command prompt from java (this black
dos window...)
I want to execute some dos command and to execute them using java code
that will run them inside that black dos window...

I know I can use...
Runtime.getRuntime().exec("run.bat", null);
and get a handle to its inputStream however this is not what I want
since I want to open that run.bat in the dos prompt ...

Execute "cmd.exe /k run.bat" to execute run.bat and keep the command window
open afterwards.

--
JustThe.net Internet & New Media Services, Apple Valley, CA PGP: 0xE3AE35ED
Steven J. Sobol, Geek In Charge / 888.480.4NET (4638) / (e-mail address removed)
Domain Names, $9.95/yr, 24x7 service: http://DomainNames.JustThe.net/
"someone once called me a sofa, but i didn't feel compelled to rush out and buy
slip covers." -adam brower * Hiroshima '45, Chernobyl '86, Windows 98/2000/2003
 
T

Tomer Ben-David

Hi

Is there any way to open the dos command prompt from java (this black
dos window...)
I want to execute some dos command and to execute them using java code
that will run them inside that black dos window...

I know I can use...
Runtime.getRuntime().exec("run.bat", null);
and get a handle to its inputStream however this is not what I want
since I want to open that run.bat in the dos prompt ...

its ok I found the solution

Runtime.getRuntime().exec("cmd /c start run.bat");

:)

However Now im facing another problem, anyone knows how can I redirect
the output of the dos prompt to a file AND as well that it stays in
the DOS prompt black screen?

Thanks
 
R

rpnman

from the command line use redirection ">" as in
Dir *.java>javaFiles.txt

I suspect, but I do not know, that you'll be able to include this in command
lines passed to .getRuntime().exec() as well.

You may need to enclose the command line in quotes and use the /S switch as
well..

From a dos prompt, try cmd /? for more details on the switches for the cmd
executable.

I'd be interested in hearing the results of your experiments.
 
T

Tomer Ben-David

Hi

I found your articles very interesting and very clear! and i looked at
the exec utility that simplifies things, and read about the
inputstream issue with the process however, I dindnt find any clue
whether its possible to direct the output BOTH to a file AND to the
console! Im currently going to use, java service wrapper it kind of
performing it, it might interest you as well...
 
T

Tomer Ben-David

Hi, I played with it and didnt find any way to perform this. I'm
going to use java service wrapper (a simple search for "java service
wrapper") will direct you to it, since im going to be using a service
as well i found it usefull (and it did print the output of the dos
command both to the dos window and to a file...)

Tomer
 
L

Liz

rpnman said:
from the command line use redirection ">" as in

I suspect, but I do not know, that you'll be able to include this in command
lines passed to .getRuntime().exec() as well.

You may need to enclose the command line in quotes and use the /S switch as
well..

From a dos prompt, try cmd /? for more details on the switches for the cmd
executable.

I'd be interested in hearing the results of your experiments.

NAME
tee -- clone output stream

SYNOPSIS
tee [-ai] [file...]

DESCRIPTION
The tee command clones an output stream. It copies
each output file as well as to the standard output.
 
R

Roedy Green

I found your articles very interesting and very clear! and i looked at
the exec utility that simplifies things, and read about the
inputstream issue with the process however, I dindnt find any clue
whether its possible to direct the output BOTH to a file AND to the
console! Im currently going to use, java service wrapper it kind of
performing it, it might interest you as well...

see http://mindprod.com/jgloss/tee.html
 
Joined
Feb 22, 2009
Messages
1
Reaction score
0
If anybody help me to execute following DOS commands using java

c:\> d:
d:\> cd jdk1.6\bin
d:\jdk1.6\bin\> javac mine.java
d:\jdk1.6\bin\> java mine

i want to execute the mine.java using another java program..
Please help me.. It is important in my project please help me
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top