Listing 1. Module1.vb

'  Copyright (c) 2006 Anatoly S. Krivitsky, PhD. All rights reserved.
'  Conditional permission for free use of the code. As soon as above copyright notes are mentioned, the author grants a
 permission to any person or organization to use, distribute and publish this code for free.
'  Questions and comments may be directed to the author at akrivitsky@yahoo.com and akrivitsky@gmail.com.
'  Disclaimer of Liability
'  The user assumes all responsibility and risk for the use of this code "as is".
'  There is no  warranty of any kind associated with the code.
'  Under no circumstances, including negligence, shall the author be liable for any DIRECT, INDIRECT, INCIDENTAL,
 SPECIAL or CONSEQUENTIAL DAMAGES, or LOST PROFITS that result from the use or inability to use the code.
'  Nor shall the author be liable for any such damages including, but not limited to, reliance by any person on any
information obtained with the code

Imports System.Windows.Forms
Imports System.Diagnostics
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        Dim myProcess As Process = New Process()
        Dim errors As String
        Dim psi As New _
        System.Diagnostics.ProcessStartInfo("C:\cygwin\cygwin.bat")
        Dim arguments As [String]() = Environment.GetCommandLineArgs()
        Dim FileName As String = arguments(1)
        Dim pathToDirectory As String = arguments(2)
        Console.WriteLine("File Name = " & FileName)
        Console.WriteLine("pathToDirectory = " & pathToDirectory)
        Dim split As String() = Nothing
        Dim delimStr As String = ":\."
        Dim delimiter As Char() = delimStr.ToCharArray()
        split = pathToDirectory.Split(delimiter)
        Dim directoryName As String = split(split.Length - 1)
        Dim CygwinCdCommand As String = "cd /home/Anatoly/" & _
        directoryName & "{ENTER}"
        split = FileName.Split(delimiter)
        Dim FileNameWithoutExtension = split(0)
        Dim g77Call As String = "g77 -O " & _
        FileName & " -o " & FileNameWithoutExtension & ".exe{ENTER}"
        psi.RedirectStandardOutput = True
        psi.RedirectStandardError = True
        psi.WindowStyle = ProcessWindowStyle.Hidden
        psi.UseShellExecute = False
        myProcess = System.Diagnostics.Process.Start(psi)
        Dim myOutput As System.IO.StreamReader _
        = myProcess.StandardOutput
        Dim g77Errors As System.IO.StreamReader _
        = myProcess.StandardError
        If myProcess.Responding Then
            System.Windows.Forms.SendKeys.SendWait( _CygwinCdCommand)
            System.Windows.Forms.SendKeys.SendWait( _g77Call)
           System.Windows.Forms.SendKeys.SendWait( _"exit{ENTER}")
            errors = g77Errors.ReadToEnd()
            Dim pathTog77Output As String
            pathTog77Output = pathToDirectory & "\g77Output.txt"
            If File.Exists(pathTog77Output) Then
                File.Delete(pathTog77Output)
            End If
            Console.WriteLine("pathTog77Output = " & pathTog77Output)
            Dim sw As StreamWriter = New StreamWriter(pathTog77Output)
            sw.Write(errors)
            sw.Flush()
            sw.Close()

        Else
            myProcess.Kill()
        End If
        myProcess.WaitForExit(2000)
        myProcess.Close()
        Dim myNotepad As Process = New Process()
        myNotepad.StartInfo.FileName = "notepad"
        myNotepad.StartInfo.WindowStyle = _
        System.Diagnostics.ProcessWindowStyle.Normal
        myNotepad.EnableRaisingEvents = True
        myNotepad.Start()
        myNotepad.WaitForInputIdle(1000)
        If myNotepad.Responding Then
            System.Windows.Forms.SendKeys.SendWait( _
            errors)
        Else
            myNotepad.Kill()
        End If

   End Sub

End Module