473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems With Reading RedirectedOutput Of Command Line Program.

CMG
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.CurrentDirectory & "\"
Private pngimage As String = startuppath & "verify.png"
Private png2pnm As String = startuppath & "png2pnm.exe"
Private gocr As String = startuppath & "gocr.exe"
Dim batfile As String = "@ECHO OFF" & vbCrLf & """C:\program
files\IrfanView\i_view32.exe"" verify.png /swap_bw /convert=flip.png" &
vbCrLf & "png2pnm.exe flip.png verify.pnm" & vbCrLf & "gocr verify.pnm"

Sub Main()

Try
downloadFile(args(1), pngimage)
Dim sw As System.IO.StreamWriter = New
System.IO.StreamWriter(startuppath & "process.bat")
sw.Write(batfile)
sw.Flush()
sw.Close()
Catch
End Try

Dim cmgProc As New System.Diagnostics.Process
Dim i As New System.Diagnostics.ProcessStartInfo
i.FileName = "process.bat"
i.Arguments = Nothing
i.RedirectStandardError = False
i.RedirectStandardInput = True
i.RedirectStandardOutput = True
i.CreateNoWindow = True
i.UseShellExecute = False
cmgProc.StartInfo = i
Try
cmgProc.Start()
Console.WriteLine(cmgProc.StandardOutput.ReadToEnd )
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.FileName = "cmd.exe"
p.StartInfo.UseShellExecute = False
p.StartInfo.CreateNoWindow = True
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = False
p.StartInfo.RedirectStandardError = True

p.Start()

Dim swIn As System.IO.StreamWriter = p.StandardInput
Dim swOut As System.IO.StreamReader = p.StandardOutput()
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.Diagnostics.Process.Start(STARTUPPATH & "bin\gocr.bat")

System.Threading.Thread.Sleep(333)
Dim sr As System.IO.StreamReader = New
System.IO.StreamReader(STARTUPPATH & "\bin\pwnd.ViRi")

Dim strOcrResult As String = sr.ReadToEnd.Trim
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/
Jul 21 '05 #1
0 1151

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Christopher | last post by:
I am trying to get a line from the user which could be anything, I am expecting either a string followed by a whitespace or just a string by itself. I have tryed using string::getline,...
3
by: Max | last post by:
Yea this is probably a n00b question, but I haven't programmed C++ in at least 2 years and have never programmed for unix, sorry :) Anyway, I have a project in which a program is required to read...
2
by: Kyriakos Stavrou | last post by:
I deployed my project and made a file association, let say that the extension is .xyz Up to here all works fine. The problems i have are : 1. In the file types editor a verb named "open" is...
0
by: CMG | last post by:
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...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
3
by: sir.linying | last post by:
My php script is to call perl scipt which makes use of Spreadsheet::ParseExcel module to parse Excel file. I am able to launch php script from command line so that perl script can run and properly...
2
by: sani8888 | last post by:
Hi everybody I am a beginner with C++ programming. And I need some help. How can I start with this program *********** The program is using a text file of information as the source of the...
4
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on...
5
by: sayeo87 | last post by:
Hi, I am quite new to JSP so please forgive me if I ask really simple things... I am trying to run system commands on the server and display the output on a webpage. This is what I've got: <%@...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.