control/ send input to external application

PackElend

New member
Joined
Nov 14, 2007
Messages
2
Programming Experience
1-3
Hi folks,

I want to write a small exe with Visual Studio 05 to control an external dos-prgramm.
For the beginning I used this one:

VB.NET:
Module Module1

Sub main()

Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()

myProcess.StartInfo.FileName = pfad3

myProcess.StartInfo.CreateNoWindow = False

myProcess.StartInfo.UseShellExecute = False

myProcess.StartInfo.RedirectStandardInput = True

myProcess.Start()

myProcess.StandardInput.WriteLine("cd " & pfad2)

myProcess.WaitForExit()   'else it closes immediately

End Sub

End Module

It opens the command prompt and instert the test which is executed by the command prompt. That's fine but after that I can't write any word it doesn't accept any input anymore, why?

By the way ist there way too just write an word without line break, like

VB.NET:
myProcess.StandardInput.Write("cd " & pfad2)

I found some examples that start with and useing


VB.NET:
Dim myProcess As Process = New Process()

Dim sIn As StreamWriter = myProcess.StandardInput

sIn.AutoFlush = True

sIn.Write("some text")
What's the difference?

The only way out I know is sendkeys but is more a *headtroughthewall* method.


thx


stefan
 
Last edited by a moderator:
If you're going to refer to any property value multiple times you should assign it to a local variable first. This:
VB.NET:
myProcess.StandardInput.Write("Hello")
myProcess.StandardInput.Write("World")
is inefficient because it has to go through the property to get the same object twice. This:
VB.NET:
Dim sIn As StreamWriter = myProcess.StandardInput

sIn.Write("Hello")
sIn.Write("World")
is more efficient because accessing the object via the local variable the second time is quicker than going through the property to get it again.
 
Back
Top