0

I have recently found this application called zbarcam that is a command prompt application that reads QR Codes from my webcam. It works great when I run it from the command prompt and it displays all the QR Code texts in the command prompt.

Now I am trying to integrate its functionality into my VB.Net project, but, although I can load the application using StartInfo, I cannot read the QR codes that are displayed in the command prompt.

Here is the code I am using:

    Dim myprocess As New Process

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    With myprocess
      .StartInfo.FileName = "C:\Progra~2\ZBar\bin\zbarcam"
      .StartInfo.RedirectStandardOutput = True
      .StartInfo.UseShellExecute = False
      .Start()
    End With
    Timer1.Enabled = True
    Timer1.Start()
  End Sub

  Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    resultsTextBox.Text = myprocess.StandardOutput.ReadToEnd
  End Sub

What I want to do is check for changes in the text in the command prompt once every second. However, when I run this code, the command prompt comes up as black and when I move my code in front of the camera, although it detects it (I can see the green box around the QR Code in the video preview), the text does not show in the command prompt.

If I set ".StartInfo.UseShellExecute" to True and comment the line ".StartInfo.RedirectStandardOutput = True" and disable the timer, then the qr codes start showing in the command prompt, but I cannot read them!

What is the best way to go about this? Ideally I wish to read from the command prompt only when there is a change, but if this cannot be done, then the next best thing is to poll the command prompt once a second and check for changes.

Osprey
  • 1,523
  • 8
  • 27
  • 44
  • Can you clarify if `RedirectStandardOutput` works for other command line apps just not zbarcam? – Jeremy Thompson Jul 16 '12 at 06:21
  • Any suggestions as to what I can test it with? Thanks! – Osprey Jul 16 '12 at 08:41
  • Just make a simple Console application that outputs data. Sort of like this quy: http://stackoverflow.com/questions/4453535/how-do-i-redirect-a-console-programs-output-to-a-text-box-in-a-thread-safe-way – Jeremy Thompson Jul 16 '12 at 08:45
  • Thanks, Jeremy. Unfortunately I don't know how to write a console application. And the example given is in C#. All I want is a code snippet to open a command prompt, run a command in it (the one to start running zbarcam), and read what is in the command prompt console once every second. It appears to be a simple task, but all examples I found require the console to be closed soon after the command is issued. I need it to remain open and read from at regular intervals. – Osprey Jul 16 '12 at 09:46
  • 1
    Why have I been given a -1 vote? What did I do wrong? – Osprey Jul 16 '12 at 12:33

0 Answers0