0

I’m trying to run an external (non-GUI) application and use RedirectStandardInput and RedirectStandardOutput to send data to and receive data from this application to a TextBox. The main problem is that this application uses a command prompt to interact with the user:

IBM Spectrum Protect Command Line Administrative Interface - Version 8, Release 1, Level 15.0 (c) Copyright by IBM Corporation and other(s) 1990, 2022. All Rights Reserved.

Session established with server SERVER1: Linux/x86_64 Server Version 8, Release 1, Level 13 Server date/time: 08-11-2022 13:54:54 Last access: 08-11-2022 13:41:51

Protect: SERVER1>

At this prompt, you can enter commands, which can return a lot of output, that’s why this application prompts the user for enter, to scroll through each screen:

Protect: SERVER1>help

Command line Help for the IBM Spectrum Protect for Linux server Version 8.1.13

Contents

1.0 Managing the server from the command line

1.1 Issuing commands from the administrative client

1.1.1 Starting and stopping the administrative client

1.1.2 Monitoring server activities from the administrative client

1.1.3 Monitoring removable-media mounts from the administrative client

1.1.4 Processing individual commands from the administrative client

1.1.5 Processing a series of commands from the administrative client

1.1.6 Formatting output from commands

1.1.7 Saving command output to a specified location

1.1.8 Administrative client options more...   (<ENTER> to continue, 'C' to cancel)

Here, the user can use the enter key to go to the next screen or enter ‘c’ to cancel the command. I currently use a form with TextBox1 for input and TextBox2 for output. The downside is that I no longer see the command prompt SERVER1>. Also, the scroll-one-page-at-a-time feature is also no longer working, all output is written to TextBox2 in one go. I have two questions:

  1. Is it at all possible to use one single Textbox for both input and output, just like the original window does?
  2. How can I make sure all lines are written to StandardOutput, so including the command prompt and also including the more... (<ENTER> to continue, 'C' to cancel) when command output is more than one page?

Please find my current code down below. Thank you very much for any help in advance!

Kind regards, Eric van Loon

Public Class Form1
    Dim WithEvents P As New Process
    Dim SW As System.IO.StreamWriter
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        P.EnableRaisingEvents = True
        Me.Text = "My title"
        AddHandler P.OutputDataReceived, AddressOf DisplayOutput
        P.StartInfo.CreateNoWindow() = True
        P.StartInfo.UseShellExecute = False
        P.StartInfo.RedirectStandardInput = True
        P.StartInfo.RedirectStandardOutput = True
        P.StartInfo.FileName = "dsmadmc.exe"
        P.StartInfo.Arguments = ""
        P.Start()
        P.SynchronizingObject = Me
        P.BeginOutputReadLine()
        SW = P.StandardInput
        SW.WriteLine()
    End Sub
    Private Sub DisplayOutput(ByVal sendingProcess As Object, ByVal output As DataReceivedEventArgs)
        TextBox1.AppendText(output.Data() & vbCrLf)
    End Sub
    Private Sub Textbox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        If e.KeyChar = Chr(Keys.Return) Then
            SW.WriteLine(TextBox2.Text)
        End If
    End Sub
    Private Sub myProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles P.Exited
        Me.Close()
    End Sub End Class
Eric van Loon
  • 103
  • 1
  • 9
  • Does this answer your question? [Running an external app in textbox (how to preserve all functionality?)](https://stackoverflow.com/questions/74349449/running-an-external-app-in-textbox-how-to-preserve-all-functionality) – Tu deschizi eu inchid Nov 08 '22 at 14:41
  • The following may be helpful: https://stackoverflow.com/a/51682585/10024425 – Tu deschizi eu inchid Nov 08 '22 at 15:01
  • Hi @user9938, I found a fix for the prompt issue, so that's fixed now. I tried (also the code from the page in your second update) and it's not working for my application. Basically, it's also not working for a simple cmd.exe. If you start cmd.exe outside of VB and enter `dir /p c:\windows` you get one screen at a time. If you start cmd.exe and redirect input and output to a textbox, the /p switch no longer seems to be working and the whole output is showed. – Eric van Loon Nov 09 '22 at 13:42

0 Answers0