Free

Free coded apps to suit all. No sign up, no email, usable offline, updates when I can, feedback welcome. Send feedback

How-to

How to OCR a picture from the command line

Read by Zaweba has a command line: --grab-text reads a picture, copies its text to the clipboard and exits with a code your script can check.

How to OCR a picture from the command line

You can run Read by Zaweba from the command line. The command ZawebaRead.exe --grab-text file.png reads the picture, copies the text to the clipboard, shows a short notice and exits. Adding --review opens Read so you can check the result, and the exit code tells a script what happened.

That makes OCR something you can wire into other tools: a batch file, a shortcut, a script that runs after a screenshot is saved, or another program with a button that hands a picture over. Snap by Zaweba's Copy text button works exactly this way.

The commands

There are three ways to start Read from a command line, all on ZawebaRead.exe.

With file or folder names after it, Read opens them in the window as if you had dropped them there. That's handy for a shortcut or a Send To entry that opens pictures straight in Read.

With --grab, Read starts a screen text grab: the screen freezes and you drag round the text you want, just as when you press the hotkey.

With --grab-text followed by a picture file, Read reads the picture without opening its window, copies the text to the clipboard, shows a notice and exits. Add --review after the file name to open the result in Read instead, so you can check it and correct it.

Exit codes

When --grab-text finishes, it returns an exit code. 0 means the text was copied. 1 means no text was found in the picture. 2 means the picture couldn't be read. 3 means the clipboard was busy, which can happen if another program was holding on to it at that moment.

A script can act on these. On 0 it can carry on; on 1 or 2 it can tell you; on 3 it can wait a moment and try again. In a Windows batch file the code is in ERRORLEVEL, and in PowerShell it's in LASTEXITCODE.

Putting it to work

The simplest use is a desktop shortcut or a context menu entry that runs --grab-text on a picture, so reading a screenshot is one click. Another is to pair it with a capture tool that saves pictures to a folder and can run a command afterwards.

Snap by Zaweba shows the pattern. Its Copy text button runs Read's --grab-text on the capture and puts the text on the clipboard; holding Shift opens Read for checking, which is the --review route. Snap does the capturing and Read does the reading, without either app needing to know much about the other.

What the command line doesn't do

--grab-text is meant for one picture at a time, with the clipboard as its output. For a whole folder of scans saved as documents, use the Batch tab in Read's window instead. It reads a folder or a set of files in the background, into one combined document or a set of files per picture, in the formats ticked on the Output tab, and reports files it couldn't read without stopping.

The reading itself is the same either way. Read chooses an engine, cleans up the picture where needed and reads it on your PC, with nothing uploaded. If the result matters, --review gives you the side-by-side check before the text goes anywhere, with Read by Zaweba's amber shading on words it's unsure of.