Redirecting standard input, but not output
Hi. I want to redirect a VB Console App input to my VB Winform app, but I want that the console's output remains on the default.
So when I press a button in VB WinForm app, writes line to the console app, and it shows it.
The problem is, that the console app remains blank, even though it gets the transmitted message.
WinForm app code:
Code:
console_process = New Process
console_process.StartInfo.FileName = "C:\Users\David\OneDrive\Workspace\Visual Basic\server-console\server-console\bin\Debug\server-console.exe"
console_process.StartInfo.UseShellExecute = False
console_process.StartInfo.WorkingDirectory = "C:\Users\David\OneDrive\Workspace\Visual Basic\server-console\server-console\bin\Debug"
console_process.StartInfo.RedirectStandardInput = True
console_process.StartInfo.RedirectStandardOutput = False
console_process.Start()
'When button is pressed:
console_process.StandardInput.WriteLine("Test")
ConsoleApp code:
Code:
Sub Main()
While True
Dim line = Console.ReadLine()
Console.WriteLine(line)
End While
End Sub
Re: Redirecting standard input, but not output
Just a tip, look up property initializers at: https://learn.microsoft.com/en-us/do.../dim-statement - it doesn't answer your question but can improve your code.
EDIT:
Also check:
-System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
-System.IO.Path.Combine()
Furthermore, I reread your post and it makes no sense to me. You should try rephrasing your question.
Re: Redirecting standard input, but not output
So, I do have a WinForm app from where I want to send commands to my Console app.
In my WinForm app I start the process of the console, and redirect the input, therefore I can send input with the function
Code:
console_process.StandardInput.WriteLine("Test")
.
Then, my Console app should get it in his standard input, with this row:
Code:
Dim line = Console.ReadLine()
, and then I want to print it on the console with the
Code:
Console.WriteLine(line)
.
The problem is, that there will be nothing printed on the console after it runs. I hope now it's understandable.
Re: Redirecting standard input, but not output
This is also off topic but, when copying your code, you have made the same mistake that many people do. You have placed the cursor before the first character of the first line and then dragged from there. That's how you end up with no leading whitespace on the first line and a wad of leading whitespace on every other line, making the code harder to read for two reasons. Instead, hold down the Alt key, then click and drag. That will select a rectangular block of text, so it will trim the leading whitespace off every line. Of course, you could have trimmed the whitespace manually if you didn't know that trick, in an effort to help us to help you by making your code easier to read.