AWestEng
asked on
Processes: StandardInput/StandardOutput
Hi guys!
I really need some help to sort this out!
The code I have dosent work so I need help to see what I have done wrong, EXPERT help needed!!!
I have 2 applications: App1 and App2
1: In App1 I send a command to App2
2: In App1 I like to know if this command was executed as it should, so I need some data back from App2
This is the code!
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
This is just pseudocode
I must use the process StandardInput/StandardOutp ut method, nothing else..
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
Thx
I really need some help to sort this out!
The code I have dosent work so I need help to see what I have done wrong, EXPERT help needed!!!
I have 2 applications: App1 and App2
1: In App1 I send a command to App2
2: In App1 I like to know if this command was executed as it should, so I need some data back from App2
This is the code!
--------------------------
This is just pseudocode
I must use the process StandardInput/StandardOutp
--------------------------
Thx
In App1
--------------------------------------------------
Dim myprocess As New Process
Dim processData As String
With myprocess.StartInfo
.FileName = applicationPath & server & ".exe"
.Arguments() = "/input=True,True"
.CreateNoWindow = False
.ErrorDialog = False
.UseShellExecute = False
.RedirectStandardOutput = True
.RedirectStandardError = True
.RedirectStandardInput = True
.WindowStyle = ProcessWindowStyle.Normal
End With
myprocess.Start()
Dim standardOutput As IO.StreamReader = myProcess.StandardOutput
'// Wait for Exited event, but not more than 10 seconds.
Const SLEEP_AMOUNT As Integer = 100
Do While Not m_shutDownProcessExited
m_shutDownElapsedTime += SLEEP_AMOUNT
'// Read the standard output of the spawned process.
processData = standardOutput.ReadToEnd
If Not String.IsNullOrEmpty(processData) Then
Exit Do
End If
'// Timout?
If m_shutDownElapsedTime > 10000 Then
myProcess.Kill()
Exit Do
End If
Thread.Sleep(SLEEP_AMOUNT)
Loop
If processData = "True" Then
'Do some stuff
Else
' Do some other stuff
End If
In App2
--------------------------------------------------
Dim runningProcesses As Process()
Dim runningProcess As Process = Nothing
runningProcesses = Process.GetProcessesByName(server.FullPath)
If runningProcesses.Length > 0 Then
For Each p As Process In runningProcesses
If p.ProcessName = server.Name Then
runningProcess = p
Exit For
End If
Next
End If
If runningProcess IsNot Nothing Then
runningProcess.StandardInput.Write("True")
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
and in App2 should I write to input to send the data back to App1?
ASKER
hmm I'll skipt the part of using the standardInput/output I'll connect via a socket instead, any tips there?
only local connection 127.0.0.1 wil be used
only local connection 127.0.0.1 wil be used
ASKER
when I tested some more now I got this error from app 2 > StandardIn has not been redirected
ASKER
I can't get it to work as I want, but that can be my bad.. But thx for trying
ASKER
when using StandardInput/StandardOutp