Solved

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

Posted on 2013-11-04
6
244 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 16

Accepted Solution

by:
hjgode earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thankyou.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

7 Experts available now in Live!

Get 1:1 Help Now