Open dos command prompt from java

Discussion in 'Java' started by Tomer Ben-David, May 16, 2004.

  1. 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, May 16, 2004
    #1
    1. Advertising

  2. 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 (4638) /
    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
    Steven J Sobol, May 16, 2004
    #2
    1. Advertising

  3. (Tomer Ben-David) wrote in message news:<>...
    > 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
    Tomer Ben-David, May 16, 2004
    #3
  4. Tomer Ben-David

    Roedy Green Guest

    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.
    Roedy Green, May 16, 2004
    #4
  5. Tomer Ben-David

    rpnman Guest

    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:...
    > (Tomer Ben-David) wrote in message

    news:<>...
    > > 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
    rpnman, May 16, 2004
    #5
  6. 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 <> 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
    Tomer Ben-David, May 18, 2004
    #6
  7. 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:...
    > > (Tomer Ben-David) wrote in message

    > news:<>...
    > > > 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
    Tomer Ben-David, May 18, 2004
    #7
  8. Tomer Ben-David

    Liz Guest

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


    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:...
    > > (Tomer Ben-David) wrote in message

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

    >
    >
    Liz, May 18, 2004
    #8
  9. Tomer Ben-David

    Roedy Green Guest

    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.
    Roedy Green, May 19, 2004
    #9
  10. Tomer Ben-David

    mrgowthamkumar

    Joined:
    Feb 22, 2009
    Messages:
    1
    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
    mrgowthamkumar, Feb 22, 2009
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted
    Replies:
    1
    Views:
    510
  2. chrisdude911
    Replies:
    10
    Views:
    135,372
    srk289
    Mar 10, 2009
  3. gaurav kashyap
    Replies:
    2
    Views:
    612
    gaurav kashyap
    Oct 30, 2008
  4. gaurav kashyap
    Replies:
    3
    Views:
    682
    gaurav kashyap
    Oct 31, 2008
  5. Mel
    Replies:
    10
    Views:
    3,111
    Sailaja Appi
    Feb 13, 2009
Loading...

Share This Page