Eghh! Gomer Pile trying to figure out Runtime.exec();

Discussion in 'Java' started by Chris, Jun 26, 2008.

  1. Chris

    Chris Guest

    All, I am having the hardest time trying to understand documentation
    regarding Runtime.exec(); That is, I am writing a java app that needs
    to make a call to another app via windows command prompt. The problem
    I am having is I cant figure out how to open the correct directory and
    then execute the command call (because of quotes in the argument of
    the command call. See below).

    The directory is located in: C:\Program Files\BLAST\BIOINFORMATICS
    \apildoc

    And the command (w/associated arguments) is: BIOCommand\text="Hello,
    Bio Entry1: HT8867" /peptides="Sc12.92"

    Does anyone have expertise in this area that could help me? Thank you
    very much for your time.




    import java.io.IOException;

    public class CmdPrompt {
    public static void main(String args[])
    {
    try {
    String command = new String[]{"cd", "\"c:\\Program Files\
    \BLAST\\BIOINFORMATICS\", "BIOCommand\text="Hello, Bio Entry1:
    HT8867" /peptides="Sc12.92""};
    Runtime.exec(command);
    }

    catch (IOException e)
    {
    }
    }
    }
     
    Chris, Jun 26, 2008
    #1
    1. Advertising

  2. Chris wrote:
    > All, I am having the hardest time trying to understand documentation
    > regarding Runtime.exec(); That is, I am writing a java app that needs
    > to make a call to another app via windows command prompt. The problem
    > I am having is I cant figure out how to open the correct directory and
    > then execute the command call (because of quotes in the argument of
    > the command call. See below).


    See <http://mindprod.com/jgloss/exec.html>.

    > String command = new String[]{"cd", "\"c:\\Program Files\
    > \BLAST\\BIOINFORMATICS\", "BIOCommand\text="Hello, Bio Entry1:
    > HT8867" /peptides="Sc12.92""};
    > Runtime.exec(command);


    Watch the 80-character width there!

    Anyways, the most important thing to know is that Runtime != bash or DOS
    or Command Prompt or whatever shell of your choice.

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
     
    Joshua Cranmer, Jun 26, 2008
    #2
    1. Advertising

  3. On Thu, 26 Jun 2008 12:58:51 -0700 (PDT), Chris wrote:
    > All, I am having the hardest time trying to understand documentation
    > regarding Runtime.exec(); That is, I am writing a java app that
    > needs to make a call to another app via windows command prompt. The
    > problem I am having is I cant figure out how to open the correct
    > directory and then execute the command call


    Runtime.exec() executes one command, not a sequence of them.

    If you want the program to run in a specific directory, then use the
    version of Runtime.exec() that lets you specify a directory (but not
    as part of the command itself).

    /gordon

    --
     
    Gordon Beaton, Jun 26, 2008
    #3
  4. Chris

    Mark Space Guest

    Chris wrote:

    > try {
    > String command = new String[]{"cd", "\"c:\\Program Files\
    > \BLAST\\BIOINFORMATICS\", "BIOCommand\text="Hello, Bio Entry1:
    > HT8867" /peptides="Sc12.92""};
    > Runtime.exec(command);


    I'm off to read the docs now, but normally you have to read the output
    of the process you run, or it'll wedge (stop). You have to drain the
    process's output stream, even if you don't do anything with the output.

    I'll see if reading the docs refreshes any other ideas in my head....
     
    Mark Space, Jun 26, 2008
    #4
  5. Chris

    Lew Guest

    Chris wrote:
    > >         String command = new String[]{"cd", "\"c:\\Program  Files\
    > > \BLAST\\BIOINFORMATICS\", "BIOCommand\text="Hello, Bio Entry1:
    > > HT8867" /peptides="Sc12.92""};
    > >    Runtime.exec(command);


    Joshua Cranmer wrote:
    > Watch the 80-character width there!


    Also, watch out for the illegal statement there, too. Near as I can
    tell without trying to compile it myself, that assignment to 'command'
    will not compile, even after deleting the Usenet word-wrap artifacts.

    --
    Lew
     
    Lew, Jun 26, 2008
    #5
  6. Chris

    Roedy Green Guest

    On Thu, 26 Jun 2008 12:58:51 -0700 (PDT), Chris
    <> wrote, quoted or indirectly quoted someone who
    said :

    >All, I am having the hardest time trying to understand documentation
    >regarding Runtime.exec(); T


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

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jun 27, 2008
    #6
    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. Randall Parker

    Trying to figure out forms authentication

    Randall Parker, Dec 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    544
    =?Utf-8?B?VmVua2F0X0tM?=
    Dec 5, 2005
  2. Hal Vaughan
    Replies:
    11
    Views:
    1,176
    Gordon Beaton
    May 22, 2006
  3. =?Utf-8?B?cm9kY2hhcg==?=

    still trying to figure out datalist event handler

    =?Utf-8?B?cm9kY2hhcg==?=, Oct 25, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    291
    =?Utf-8?B?cm9kY2hhcg==?=
    Oct 26, 2006
  4. Replies:
    2
    Views:
    541
  5. Olve
    Replies:
    2
    Views:
    238
Loading...

Share This Page