Run dos batch file from macro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Run dos batch file from macro

andyg2
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.
Reply | Threaded
Open this post in threaded view
|

Re: Run dos batch file from macro

dscho
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.htm

Having 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
Reply | Threaded
Open this post in threaded view
|

Re: Run dos batch file from macro

andyg2
In reply to this post by andyg2
Thanks for the info.
I'm very new to this and still struggling. I've been trying to implement the java here: http://hi.baidu.com/1zebra/blog/item/34ae743ee661f73a71cf6c4d.html with no luck at all but ideally I'd like a macro as I'd like to add it to an existing macro.

As I'm just testing for a rough word count, I could use the return code (0-255 batch errorlevel) for returning the count in number of binary bits needed to hold the number.  This I think, would ensure program termination and pass the needed data to ImageJ - for deciding what to do with the image.

Is there a way to do that in a macro? Or if not, how can I call a class from a macro and get the return code from that?
Some code would be great but any further pointers also very helpful.

Thanks again
Reply | Threaded
Open this post in threaded view
|

Re: Run dos batch file from macro

mikelilin
In reply to this post by andyg2
You can try this free online ocr to convert image to text.