Console application:
Dim myno As Integer = 1010
Console.WriteLine(Convert.ToString(myno))
Dim sw As New StreamWriter("filename.txt", True)
sw.Write(Convert.ToString(myno))
sw.Flush()
sw.Close()
Console.ReadLine()
Windows application:
Dim mm As New System.Diagnostics.Process
Dim info As New System.Diagnostics.ProcessStartInfo(Application.StartupPath & "\ConsoleApplication1.exe")
mm.StartInfo = info
mm.Start()
Dim f As New FileInfo(Application.StartupPath & "\filename.txt")
Dim s As StreamReader = f.OpenText
TextBox1.Text = s.ReadToEnd
If Not String.IsNullOrEmpty(TextBox1.Text) Then
mm.Kill()
End If
However the Console app doesn’t write in the textfile and the Windows app starts but won’t close.
You are immediately trying to read from the file rather than waiting until the console application is finished writing to the file. If you have control over the console application, remove that last
ReadLineso that it closes automatically once it’s done. Then you can wait for the process to end before reading from the file. If, however, you can’t make modifications to the console application, you are going to have to do something more “hacky” such as watching for the file to change, or waiting for a specified period of time and hoping that your wait time is long enough.