Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2013-11-04
6
249 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 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