0

I have two applications here, one Windows Form Application and another Console Application.

I want the windows application to send,

"1"
"2"
"3"
"4"
"5"
"6"
"7"

And then the console application should receive them in,

Dim str1 as string = "1"
Dim str2 as string = "2"
Dim str3 as string = "3"
Dim str4 as string = "4"
Dim str5 as string = "5"
Dim str6 as string = "6"
Dim str7 as string = "7"

I found this code,

Dim str as stirng = Command()

and from windows application,

Process.Start("my path to console app.exe", "the text")

This works but only one parameter is passed. I know I can use Split Functions and split them out in console if I send all string together with a character in between but is there a way for me to send all of it one by one ?

I want to star the console app, wait till it is terminated and then continue the process.

kks21199
  • 1,116
  • 2
  • 10
  • 29
  • I think you want interprocess communication for this. See http://stackoverflow.com/questions/50153/interprocess-communication-for-windows-in-c-sharp-net-2-0 – Sean Skelly Oct 12 '14 at 08:37

1 Answers1

2

If you're going to be starting the console app manually (as opposed to sending it data when it is already running), you could use command line arguments. Taken from this question we have the Sub Main for the console app:

Public Sub Main(ByVal sArgs() As String)
    If sArgs.Length = 0 Then  'If there are no arguments
        Console.WriteLine("no arguments passed")
    Else  'We have some arguments 
        Dim i As Integer = 0
        While i < sArgs.Length  'So with each argument
            Console.WriteLine("Hello " & sArgs(i) & "!") 'Print out each item
            i = i + 1  'Increment to the next argument
        End While
    End If
End Sub

Then you can use:

Process.Start("myConsoleApp.exe", "1 2 3 4 5 6 7")
Community
  • 1
  • 1
Justin Ryan
  • 1,409
  • 1
  • 12
  • 25
  • Thanks. But a question, "1 2 3 4 5 6 7" was just a example. My strings are longer, and may contain numbers/alphabets/special characters and spaces in them. Can I use ',' ? Right now i think the Array is separating the string by space ? – kks21199 Oct 12 '14 at 10:12
  • Have a look at Mark Hurd's answer to [this question](http://stackoverflow.com/questions/13097872/vb-net-how-to-pass-a-string-with-spaces-to-the-command-line) for an example of how to encapsulate your individual strings in quotes. The double-double quote is the key to happiness. – Justin Ryan Oct 12 '14 at 10:23