• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Why the command line utility hangs when invoked through java program?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need your suggestions and guidance in following task. I am using libdmtx which comes with a command line utility which reads the image files for ECC200 Data Matrix barcodes, reads their contents, and writes the decoded messages to standard output. I want to use this command line utility in my java program on linux platform. I amd using ubuntu linux. I have installed the libdmtx on my linux machine. and when I invoke the command

dmtxread -n /home/admin/ab.tif

on linux terminal it gives the decoded value of barcode in image immediately.

when I am going to invoke this command using my java program the code stuks in execution of the command and dotn gives output. it looks like the program is processing or got hang.

Following is my java code which invokes the following command

Please tell me friends where my code is going wrong.

I refered to following article but dint get any help

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1

Please guide me friends! Thank you!

Here is the new code in which I used the ProcessBuilder Class this code also giving the same output as above code that is it hangs at the line Process process = pb.start();

Please guide me to solve this problem. Thanks You!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The safest approach is to have a separate Thread for reading each stream, otherwise you are making assumptions about when the process will write to std out and std err.

This has been discussed many times in these forums.

Bill
 
Marshal
Posts: 80214
423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure it's not waiting on the readLines ?

WP
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:The safest approach is to have a separate Thread for reading each stream, otherwise you are making assumptions about when the process will write to std out and std err.

This has been discussed many times in these forums.

Bill


However, the pb.redirectErrorStream(true) should merge error and standard outputs, making them both accessible via in the process.getInputStream(), therefore one thread to consume the output should be adequate.
 
That is a really big piece of pie for such a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic