473,761 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems Reading StandardOutput

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.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/
Nov 21 '05 #1
0 1296

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

Similar topics

0
412
by: John Lewin | last post by:
I've recently discovered the value of using existing console applications in managed .net apps. Unfortunately, I've stumbled into a problem with a particular console application that check's crc info on CDs. Using either the StandardError or StandardOutput streams read, readline or peek methods causes an immediate block that doesn't release until the console app finishes it's business. I want to launch this console app and update my UI to...
0
1199
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 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"...
3
10407
by: Al Cohen | last post by:
I'll start by warning that I'm a newbie to C# (but I've been programming for 25 years), so I may just be doing something reallyreally dumb. I'm writing a C# wrapper for a command-line application (pscp.exe, a secure file-copy app that's part of the excellent PuTTY SSH package). Getting pscp.exe to run properly was a piece of cake using the System.Diagnostics.Process class. The thing that I can't get to work is the ability to read...
2
3387
by: dansan | last post by:
I have been tryning to make some of our C# programs talk to some perl programs. These perl jewels output in binary. I have been trying to use Process.StandardOutput to read the output from the perl programs. I am able to read the output if it is ASCII (or some char of some sort). But the issues comes when it is binary info. I have tried to use StandardOutput.BaseStream, which returns a Stream to then read the bytes out of that...
1
8879
by: JC | last post by:
I'm trying to create a GUI wrapper for dumpbin, and so I'm using the Process class to run the command-line application. The problem is that if I use Readline() to get the output from the commandline app, it will hang when it comes to the command-prompt (there's no return to send it to readline). Here's the code: public bool RunCommands(string cmds, ArrayList files) {
2
1616
by: palaga | last post by:
Hi I'm starting an external process that writes data to stdout, and I want to get back these data. So I use myProcess.StandardOutput (everything is correctly set, I can read the data). to read data, I use myProcess.StandardOutput.ReadLine( ). (the data is text). The doc says that if there is no more data available, the function ReadLine return null.
4
3611
by: Eric ST | last post by:
Hi there, I run a process that run ftp.exe -s i get the StandardOutput this way : ftpProgram = Process.Start(ftpProgram.StartInfo) Output = ftpProgram.StandardOutput.ReadToEnd ftpProgram.WaitForExit() From my computer i get the output ok :
1
1479
by: Yash | last post by:
Hi, Through my VB .NET code , I am trying to invoke a perl script. My aim is to write lines to the script and read from it. With ProcInfo .Arguments = Enricher.EnrichScript + " " + enArgs .RedirectStandardInput = True .RedirectStandardOutput = True .RedirectStandardError = True .UseShellExecute = False .CreateNoWindow = True
4
15076
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that this program returns. I'm just missing the stepshere. I know that I can set the Shell command to an integer,but this only returns a 0 to me telling me that it executed, notwhat is being returned to the console by that application. Isthere a way to...
0
9554
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.