Hi,
On Mon, 8 Nov 2010, Derek Smithe wrote:
> I have a command line OCR app which counts words on a scanned page. How
> can I:
>
> a) Execute the command line from a macro
> b) Wait for execution to end before continuing
> c) Read the text output into a variable
>
> I've tried var = Runtime.getRuntime().exec("cmd.exe /c start
> c:\test.bat"); and a few variations but nothing seems to happen.
>
> I'm very new to Java and batch programming so any help would be much
> appreciated.
First of all, you need to make up your mind whether you want to use macro
language (suggested by the first part of your mail) or Java (suggested by
your use of the Runtime class, whose return value -- a Process -- you
seem to store in a variable, but do not do anything more with, such as
waitFor() its termination or getErrorStream()).
Then, if you use "start" it is no wonder that you cannot wait for the end
of the execution of the program, since the whole purpose of start is to
launch something and return. If you want to wait for it, either do not use
the "start" command, or use the "/wait" command-line option:
http://www.computerhope.com/starthlp.htmHaving said that, depending on your program, it might _still_ be
impossible to wait for it to end. If this is the case, it is _very_ much
dependent on the program whether you can come up with a workaround (i.e.
polling a file for existence/locks).
Ciao,
Johannes