Problem using DOS program from java

N

Noel

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
 
P

Pushkaraj

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

Lars Enderin

Pushkaraj said:
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.
 
P

Pushkaraj

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

Noel

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
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top