Problem using DOS program from java

Discussion in 'Java' started by Noel, Nov 11, 2008.

  1. Noel

    Noel Guest

    Dear all

    I was succesful in using a text tagging program from java and also
    gather its output. However it only functions when I use it for small
    files (3k), when I use it for slightly larger text files (8k) it does
    not work. If I use the program directly from the command prompt it
    works for files of any size.

    The problem does not lie within the 'type' dos command, as my java
    program still lists the big file.

    Here is the code

    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec("cmd /c type c:\\NLP\\EXAMPLES\\Text | c:\\NLP\
    \bin\\nlp.cmd -show_tags");

    InputStream inStd = pr.getInputStream();
    InputStreamReader inStdR = new InputStreamReader(inStd);
    BufferedReader bStd = new BufferedReader(inStdR);

    String line=null;

    while((line=bStd.readLine()) != null)
    {
    System.out.println(line);
    }

    Does anyone know why big files cannot be tagged from java, but can be
    tagged from the command prompt.

    Thanks
    N
    Noel, Nov 11, 2008
    #1
    1. Advertising

  2. Noel

    Pushkaraj Guest

    On Nov 11, 11:26 am, Noel <> wrote:
    > Dear all
    >
    > I was succesful in using a text tagging program from java and also
    > gather its output. However it only functions when I use it for small
    > files (3k), when I use it for slightly larger text files (8k) it does
    > not work. If I use the program directly from the command prompt it
    > works for files of any size.
    >
    > The problem does not lie within the 'type' dos command, as my java
    > program still lists the big file.
    >
    > Here is the code
    >
    > Runtime rt = Runtime.getRuntime();
    > Process pr = rt.exec("cmd /c type c:\\NLP\\EXAMPLES\\Text | c:\\NLP\
    > \bin\\nlp.cmd -show_tags");
    >
    > InputStream inStd = pr.getInputStream();
    > InputStreamReader inStdR = new InputStreamReader(inStd);
    > BufferedReader bStd = new BufferedReader(inStdR);
    >
    > String line=null;
    >
    > while((line=bStd.readLine()) != null)
    > {
    >         System.out.println(line);
    >
    > }
    >
    > Does anyone know why big files cannot be tagged from java, but can be
    > tagged from the command prompt.
    >
    > Thanks
    > N



    It worked on my computer, with data file of 15Kb.
    I used Process pr = rt.exec("cmd /c type c:\\delmelab\\a.txt | grep
    ';'"); here I am using grep of cygwin environment, may be the batch
    script you are using causing the problem.

    Will you able to share the script to try the same in our environment.
    Pushkaraj, Nov 11, 2008
    #2
    1. Advertising

  3. Noel

    Lars Enderin Guest

    Pushkaraj wrote:

    > It worked on my computer, with data file of 15Kb.
    > I used Process pr = rt.exec("cmd /c type c:\\delmelab\\a.txt | grep
    > ';'"); here I am using grep of cygwin environment, may be the batch
    > script you are using causing the problem.
    >
    > Will you able to share the script to try the same in our environment.

    You can use cygwin grep with ';' as first and the file path as second
    argument. No need to use a pipe.
    Lars Enderin, Nov 11, 2008
    #3
  4. Noel

    Pushkaraj Guest

    On Nov 11, 6:18 pm, Lars Enderin <> wrote:
    > Pushkaraj wrote:
    > > It worked on my computer, with data file of 15Kb.
    > > I used Process pr = rt.exec("cmd /c type c:\\delmelab\\a.txt | grep
    > > ';'"); here I am using grep of cygwin environment, may be the batch
    > > script you are using causing the problem.

    >
    > > Will you able to share the script to try the same in our environment.

    >
    > You can use cygwin grep with ';' as first and the file path as second
    > argument. No need to use a pipe.


    you are giving solution to my code, thanks for that.
    Here with 'pipe in command' I was checking if there is any problem
    with if we invoke it with java.
    Pushkaraj, Nov 11, 2008
    #4
  5. Noel

    Noel Guest

    Hello All and thanks for your replies

    The problem was that a deadlock was being created when the program was
    waiting for one of the streams to empty and the stream is not being
    emptied since it is waiting for something else.

    It was solved by my teacher by creating two threads, one for the
    InputStream and one for the ErrorStream which write their contents
    indipendently from the main program.

    Thanks again and have a nice day
    N
    Noel, Nov 11, 2008
    #5
    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. Ben Fairbank
    Replies:
    2
    Views:
    5,405
  2. john san
    Replies:
    19
    Views:
    730
    Diez B. Roggisch
    Feb 18, 2005
  3. ~neil~
    Replies:
    7
    Views:
    540
    George Fulk
    Sep 28, 2004
  4. tomhr
    Replies:
    27
    Views:
    1,402
    Mike Wahler
    Jan 12, 2006
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    267
    Michele Dondi
    Jan 22, 2004
Loading...

Share This Page