Hello,
I'm having trouble writing to a file. I can open notepad ok, but I cannot write a string to it. What am missing here? TIA.

Imports System.IO
Module Module1

    Sub Main()
        Dim start_info As New ProcessStartInfo("notepad.exe")
        start_info.UseShellExecute = False
        start_info.ErrorDialog = False
        start_info.RedirectStandardInput = True
        start_info.RedirectStandardOutput = True
        start_info.RedirectStandardError = True

        Dim proc As New Process
        proc.StartInfo = start_info
        proc.Start()

        Dim stdERRreader As StreamReader = proc.StandardError
        Dim stdINwriter As StreamWriter = proc.StandardInput
        Dim stdOUTreader As StreamReader = proc.StandardOutput

        System.Threading.Thread.Sleep(500)
        ' send data
        stdINwriter.WriteLine("TEXT FROM VB")

        stdINwriter.Flush()
        stdINwriter.Dispose()

        ' clean up
        stdERRreader.Close()
        stdINwriter.Close()
        stdOUTreader.Close()
        proc.WaitForExit()
    End Sub
End Module

You may try SendKeys.Send("TEXT FROM VB") instead of stdINwriter.WriteLine("TEXT FROM VB") SendKeys.Send() sends keystrokes to the active window. However, it's not a very reliable method. If the process you started loses focus, it won't receive those keystrokes.

You may try SendKeys.Send("TEXT FROM VB") instead of stdINwriter.WriteLine("TEXT FROM VB") SendKeys.Send() sends keystrokes to the active window. However, it's not a very reliable method. If the process you started loses focus, it won't receive those keystrokes.

Shell("Notepad.exe")
use this command to open notepad than u can write

You may try SendKeys.Send("TEXT FROM VB") instead of stdINwriter.WriteLine("TEXT FROM VB") SendKeys.Send() sends keystrokes to the active window. However, it's not a very reliable method. If the process you started loses focus, it won't receive those keystrokes.

SendKeys is working for me. I make the window active first then make the call to SendKeys.

This question has already been answered. Start a new discussion instead.