Solved

Processes: StandardInput/StandardOutput

Posted on 2008-10-13
6
943 Views
Last Modified: 2013-11-07
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/StandardOutput method, nothing else..
---------------------------------------------------------------------------------------------------------------------------

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

Open in new window

0
Comment
Question by:AWestEng
  • 5
6 Comments
 
LVL 11

Accepted Solution

by:
AkisC earned 500 total points
ID: 22709173
try if this works

replace line 22 - 37 with
'// Wait for Exited event, but not more than 10 seconds.
myprocess.WaitForExit(100000)
processData = myprocess.ExitCode

'// wait a liitle more before killing the process
Threading.Thread.Sleep(1000)
myProcess.Kill()

-ALSO-
you wrote <<I  must use the process StandardInput/StandardOutput method, nothing else..>>
If that is a limitation ok, if not why not have your App2 write a text file e.g. "App2Results.txt" and look for this text file in a do/loop node from App1?


0
 
LVL 1

Author Comment

by:AWestEng
ID: 22709717
question
when using StandardInput/StandardOutput is it not possible to send stuff between the applicaitons when a instance is running, why doesen't my code work?
0
 
LVL 1

Author Comment

by:AWestEng
ID: 22709729
and in App2 should I write to input to send the data back to App1?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:AWestEng
ID: 22709927
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
0
 
LVL 1

Author Comment

by:AWestEng
ID: 22710363
when I tested some more now I got this error from app 2 > StandardIn has not been redirected
0
 
LVL 1

Author Closing Comment

by:AWestEng
ID: 31506643
I can't get it to work as I want, but that can be my bad.. But thx for trying
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now