Results 1 to 4 of 4

Thread: Redirecting standard input, but not output

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    61

    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

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    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.
    Last edited by Peter Swinkels; Dec 9th, 2022 at 05:21 AM.

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    61

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width