I am trying to run gocr from my program, and use the output.
I have done this with success befor, with a workaround command line tool.:
Private irfanview As String = "C:\program files\IrfanView \i_view32.exe"
Private startuppath As String = Environment.Cur rentDirectory & "\"
Private pngimage As String = startuppath & "verify.png "
Private png2pnm As String = startuppath & "png2pnm.ex e"
Private gocr As String = startuppath & "gocr.exe"
Dim batfile As String = "@ECHO OFF" & vbCrLf & """C:\progr am
files\IrfanView \i_view32.exe"" verify.png /swap_bw /convert=flip.pn g" &
vbCrLf & "png2pnm.ex e flip.png verify.pnm" & vbCrLf & "gocr verify.pnm"
Sub Main()
Try
downloadFile(ar gs(1), pngimage)
Dim sw As System.IO.Strea mWriter = New
System.IO.Strea mWriter(startup path & "process.ba t")
sw.Write(batfil e)
sw.Flush()
sw.Close()
Catch
End Try
Dim cmgProc As New System.Diagnost ics.Process
Dim i As New System.Diagnost ics.ProcessStar tInfo
i.FileName = "process.ba t"
i.Arguments = Nothing
i.RedirectStand ardError = False
i.RedirectStand ardInput = True
i.RedirectStand ardOutput = True
i.CreateNoWindo w = True
i.UseShellExecu te = False
cmgProc.StartIn fo = i
Try
cmgProc.Start()
Console.WriteLi ne(cmgProc.Stan dardOutput.Read ToEnd)
Catch
End Try
End Sub
but since this is just stupid and annoying, i wanted to do it properly.
I have tried the following, but this locks up the app:
Private Function gocr()
Dim p As Process = New Process
p.StartInfo.Fil eName = "cmd.exe"
p.StartInfo.Use ShellExecute = False
p.StartInfo.Cre ateNoWindow = True
p.StartInfo.Red irectStandardIn put = True
p.StartInfo.Red irectStandardOu tput = False
p.StartInfo.Red irectStandardEr ror = True
p.Start()
Dim swIn As System.IO.Strea mWriter = p.StandardInput
Dim swOut As System.IO.Strea mReader = p.StandardOutpu t()
swIn.AutoFlush = True
swIn.WriteLine( "cd " & STARTUPPATH & vbCrLf)
swIn.WriteLine( "gocr c:\image.png" & vbCrLf)
swIn.WriteLine( "exit" & vbCrLf)
Return swOut.ReadToEnd
End Function
I have also tried, but is unpredictable in output for some reason:
Private Function gocr() As String
System.Diagnost ics.Process.Sta rt(STARTUPPATH & "bin\gocr.b at")
System.Threadin g.Thread.Sleep( 333)
Dim sr As System.IO.Strea mReader = New
System.IO.Strea mReader(STARTUP PATH & "\bin\pwnd.ViRi ")
Dim strOcrResult As String = sr.ReadToEnd.Tr im
sr.Close()
Return strOcrResult
End Function
I have tried a dozen other things, and seem unable to get a solution :(
GOCR homepage: http://jocr.sourceforge.net/