Here's some code:
it launches an exe, redirects the input to a stream object. the exe creates a text file. I read it in, parse it then display the output on the page:
Imports System.IO
Imports System.Diagnostics
Dim PROCESS_SPCS83 As Process
Dim northingInput, eastingInput As Decimal
northingInput = Me.txtNorthing.Text '818667 'values hard-coded for testing
eastingInput = Me.txtEasting.Text '1061050
Dim StationName As String = "CC15-44"
Dim n2, e2 As String
Dim logonUser As UserLogon
Try
'Coordinate Input information
'convert string to 3 decimal places as app requires it
n2 = northingInput.ToString("n3").Replace(",", "")
e2 = eastingInput.ToString("n3").Replace(",", "")
'dynamic file name (it dosen't write out the extension for some reason)
Dim sOutputFile As String = Server.MapPath(Environment.TickCount.ToString)
'args for input (StandardInput would be Keyboard)
Dim arArgs(10) As String
arArgs(0) = "2"
arArgs(1) = "Y"
arArgs(2) = "Y"
arArgs(3) = sOutputFile
arArgs(4) = "N"
arArgs(5) = StationName
arArgs(6) = n2
arArgs(7) = e2
arArgs(8) = "0600"
arArgs(9) = "N"
arArgs(10) = "N"
Dim i As Integer
logonUser = New UserLogon
logonUser.Logon("tcurtin", "kevalyeri", "")
'stream for redirecting input
Dim ArgStream As StreamWriter
PROCESS_SPCS83 = New Process
With PROCESS_SPCS83
With .StartInfo()
.FileName = Server.MapPath("SPCS83.EXE")
.RedirectStandardInput = True 'use streamwriter instread
.UseShellExecute = False
.WindowStyle = ProcessWindowStyle.Hidden
End With
.Start()
'redirect standard input from keyboard to stream
ArgStream = .StandardInput
'loop through array feeding input args (command line)
Dim bytCount As Byte = arArgs.GetLength(0) - 1
With ArgStream
For i = 0 To bytCount
.WriteLine(arArgs(i)) 'pass command line input args
Next
End With
'application normally exits after last arg, but check anyway
.WaitForExit()
End With
'assume exe has written out the file.
If File.Exists(sOutputFile) Then
Dim fs As FileStream = File.Open(sOutputFile, FileMode.Open)
Dim arBytes(), ascII() As Byte
ReDim arBytes(fs.Length)
Dim intBytesRead As Long = fs.Read(arBytes, 0, arBytes.Length)
fs.Close()
File.Delete(sOutputFile)
'convert byte array to string and re-split into array, split at carriage returns
Dim sArgs As String = System.Text.ASCIIEncoding.ASCII.GetString(arBytes)
Dim sLines() As String = sArgs.Split(vbCrLf)
For i = 0 To sLines.Length - 1
If sLines(i).IndexOf(StationName) > 0 Then
'read in the line and parse into array
Dim arPointLine() As String = sLines(i).Split(" ")
Dim northing As String = arPointLine(31) & Chr(176) & " " & arPointLine(32) & Chr(39) & " " & arPointLine(33) & Chr(34)
Dim easting As String = arPointLine(34) & Chr(176) & " " & arPointLine(35) & Chr(39) & " " & arPointLine(36) & Chr(34)
Me.lblLongitude.Text = northing
Me.lblLatitude.Text = easting
Exit For
End If
Next
Else
Me.lblMessage.Text = "File: " & sOutputFile & " Not found"
End If
Catch ex As Exception
Me.lblMessage.Text = ex.Message
Finally
If PROCESS_SPCS83 Is Nothing Then
With PROCESS_SPCS83
If Not .HasExited Then
.Kill()
PROCESS_SPCS83 = Nothing
End If
End With
End If
logonUser.LogOff()
End Try
End Sub