Solved

VB6 application writes and I want to read it through dotnet asynchronusly.

Posted on 2013-11-04
6
248 Views
Last Modified: 2013-11-06
I have an very old VB 6 application. It writes all the tracing information (hints &  messages) to a file. I have a dotnet wraper also arround this VB application.

Now I want to display this tracing info on screen through dotnet wraper. How to achieve this?

How can I read the hints & messages generated by VB application, in dot net wraper asynchronusly? Is there any best way that these both can communicate together? I don't want to read the same flat file being generated by the VB code as it can be read only after completing the writting.
0
Comment
Question by:GouthamAnand
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:hjgode
ID: 39624111
If the file is opened exclusive by the VB app, you cannot read of it before the VB app closes the file. Bad programming.

Does the VB app output any text to the console?

Do you have the code of the VB app too?
0
 

Author Comment

by:GouthamAnand
ID: 39624240
Yes, I am having the VB app code. And I am writing the code to write to standard output. But still I am not sure if I will be success in reading it from .net code.

Below 'If' condition is where the hints and messages being logged to flat file.

I am trying to write to standard output.


hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)         ' written by Goutham
    hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)       ' written by Goutham
    hConsoleErr = GetStdHandle(STD_ERROR_HANDLE)        ' written by Goutham
   
    If mbLogHints Then
   
        'iFile = stdout()
'        Open PathConcat(gConCentral.Server.FileServerRoot, "System\" & gConCentral.UID & "Hints.log") For Append As iFile
            ConsolePrint (sHint)                        ' written by Goutham
            'Print #iFile, Y2K(Now) & vbTab & sHint
           
        Close iFile
    End If
   
End Sub

'----------------------------------
'PURPOSE:   Write the string to Console. ' written by Goutham
'----------------------------------
   
Private Sub ConsolePrint(szOut As String)                           ' written by Goutham
    WriteConsole hConsoleOut, szOut, Len(szOut), vbNull, vbNull     ' written by Goutham
End Sub
0
 

Author Comment

by:GouthamAnand
ID: 39624341
Below is my .net code. WorkEngine.exe is the VB application.
below try...catch... block - 2nd 'using..' block I have written.
I haven't get any success till now.


public void DoWork123()
        {
            ProcessStartInfo start = new ProcessStartInfo();
            start.Arguments = "GOSWorkEngineApp.WorkEngine,we1,SQLREG";
           start.FileName = @"C:\Program Files\GOS\WorkEngine.exe";

            start.RedirectStandardOutput = true;
            start.RedirectStandardError = true;
            start.UseShellExecute = false;

            start.WindowStyle = ProcessWindowStyle.Hidden;
            start.CreateNoWindow = true;

            try
            {
                using (Process process = Process.Start(start))
                {
                    processId = process.Id;
                    while (!this.process.HasExited)
                    {
                        using (StreamReader reader = process.StandardOutput)
                        {
                            string result = reader.ReadToEnd();
                            Hinter.Hint.AddHint(result);
                            Console.Write(result);
                        }
                        //Thread.Sleep(1000);
                    }
                    //process.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                Hinter.Hint.AddHint(ex.Message);
                ExceptionManager.Publish(ex);
            }
        }
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 16

Accepted Solution

by:
hjgode earned 500 total points
ID: 39625031
Here is my code to capture the output of an app that writes to console and echos the read lines to the C# app console:

		void makeThumbSheet(string sFile){
			ProcessStartInfo startinfo = new ProcessStartInfo();
			startinfo.Arguments = 
				"-w 480 -h 75 -c 3 -r 4 -i -t -W -O /var/www/video \"" + sFile + "\"";
			startinfo.FileName = "/home/hgode/bin/mtn";
			startinfo.UseShellExecute=false;
			startinfo.CreateNoWindow=true;
			startinfo.LoadUserProfile=true;
			startinfo.RedirectStandardOutput=true;
			Process proc = new Process();
			proc.StartInfo=startinfo;
			Console.WriteLine("++++ creating img");
			proc.Start();

			while(!proc.StandardOutput.EndOfStream){
				string sOut = proc.StandardOutput.ReadLine();
				Console.WriteLine(sOut);
			}

			proc.Close();
		}

Open in new window


You only need to replace the process and arguments (if any).

Does your VB app echo its output to console when you start it manually in a MS-DOS console? Can you redirect the VB app output to a file using:
vbapp.exe >c:\myoutput.txt?
If both is yes, you should be able to capture the output with my above code snippet. Your VB code for console output looks like the one here http://www.angelfire.com/mi4/bvo/vb/vbconio.htm
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 39625369
You could use MSMQ to communicate between VB and .net application.VB application pushes message to MSMQ and .net application constantly listens to the queue and reads the message as it is available. Here is a link on how you can implement it.

http://jwbs-blog.blogspot.com/2009/06/using-msmq-to-communicate-between-net.html

Another approach is to write messages to the file from VB application and read the contents from .net application. Use mutex to make sure the file is accessed (write) by single application at any one point.

In VB, if you use FSO (File System Object) then you would be able to release the file as soon as the filesystem object is closed and set to nothing.
0
 

Author Closing Comment

by:GouthamAnand
ID: 39628251
Thankyou.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now