Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Open dos command prompt from java

 
Thread Tools Search this Thread
Old 05-16-2004, 02:40 PM   #1
Default Open dos command prompt from java


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 ...


Tomer Ben-David
  Reply With Quote
Old 05-16-2004, 06:05 PM   #2
Steven J Sobol
 
Posts: n/a
Default Re: Open dos command prompt from java

Tomer Ben-David <> wrote:
> 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 (463 /
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
  Reply With Quote
Old 05-16-2004, 06:18 PM   #3
Tomer Ben-David
 
Posts: n/a
Default Re: Open dos command prompt from java

(Tomer Ben-David) wrote in message news:<. com>...
> 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
  Reply With Quote
Old 05-16-2004, 06:45 PM   #4
Roedy Green
 
Posts: n/a
Default Re: Open dos command prompt from java

On 16 May 2004 10:18:44 -0700, (Tomer
Ben-David) wrote or quoted :

>
>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?


see http://mindprod.com/jgloss/exec.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
  Reply With Quote
Old 05-16-2004, 08:26 PM   #5
rpnman
 
Posts: n/a
Default Re: Open dos command prompt from java

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.

--
ROGER NEYMAN

"Tomer Ben-David" <> wrote in message
news: om...
> (Tomer Ben-David) wrote in message

news:<. com>...
> > 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



  Reply With Quote
Old 05-18-2004, 06:35 PM   #6
Tomer Ben-David
 
Posts: n/a
Default Re: Open dos command prompt from java

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...

Roedy Green <look-> wrote in message news:<>. ..
> On 16 May 2004 10:18:44 -0700, (Tomer
> Ben-David) wrote or quoted :
>
> >
> >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?

>
> see http://mindprod.com/jgloss/exec.html

  Reply With Quote
Old 05-18-2004, 06:38 PM   #7
Tomer Ben-David
 
Posts: n/a
Default Re: Open dos command prompt from java

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

"rpnman" <> wrote in message news:<pfPpc.78904$>. ..
> 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.
>
> --
> ROGER NEYMAN
>
> "Tomer Ben-David" <> wrote in message
> news: om...
> > (Tomer Ben-David) wrote in message

> news:<. com>...
> > > 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

  Reply With Quote
Old 05-18-2004, 11:43 PM   #8
Liz
 
Posts: n/a
Default Re: Open dos command prompt from java


"rpnman" <> wrote in message
newsfPpc.78904$...
> 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.


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.

> --
> ROGER NEYMAN
>
> "Tomer Ben-David" <> wrote in message
> news: om...
> > (Tomer Ben-David) wrote in message

> news:<. com>...
> > > 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

>
>



  Reply With Quote
Old 05-19-2004, 12:52 AM   #9
Roedy Green
 
Posts: n/a
Default Re: Open dos command prompt from java

On 18 May 2004 10:35:29 -0700, (Tomer
Ben-David) wrote or quoted :

>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


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump