Moola Gaming Ответов: 0

Vb.net процессы - как вы показываете, что стандартный ввод от python.exe это напрашивается на


I have a Vb.net program that runs python script in the background. I want a get the python input questions input("Enter num"). I would like to get this so I can get users to input values before writing tothe python StandardInput

VB.NET


Python - I want to ask users what's in the bracket so they can input the values

b = int(input("Enter num:"))#RUNS WHEN THERE IS ONLY THIS INPUT


Что я уже пробовал:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Me.Controls.Add(TextBox1)
      Dim p As Process = New Process
      p.StartInfo.FileName = "C:\Users\luqma\AppData\Local\Programs\Python\Python38-32\python.exe" 'Default Python Installation
      p.StartInfo.Arguments = "File.py"
      p.StartInfo.UseShellExecute = False 'required for redirect.
      p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden 'don't show commandprompt.
      p.StartInfo.CreateNoWindow = True
      p.StartInfo.RedirectStandardInput = True
      p.StartInfo.RedirectStandardOutput = True 'captures output from commandprompt.
      p.StartInfo.RedirectStandardError = True
      p.Start()
      Dim reader As StreamReader = p.StandardOutput
      Dim myStreamwrite As StreamWriter = p.StandardInput
      Dim onlyValue As Int32
      Dim part1 As String
      Dim part2 As String
      onlyValue = 1
      While Not p.StandardOutput.EndOfStream
          Dim output As String = reader.ReadLine

          If myStreamwrite.BaseStream.CanWrite Then
              myStreamwrite.WriteLine(1)
              TextBox1.Text += Environment.NewLine + ">>>" + output + Environment.NewLine
          Else
              TextBox1.Text += Environment.NewLine + ">>>" + output + Environment.NewLine
          End If
      End While

Richard MacCutchan

Если вы не показываете командное окно процесса python, то пользователь не увидит сообщение или не сможет ввести ответ. Почему вы используете кувалду, чтобы расколоть орех? VB.NET может довольно легко записывать выходные данные и считывать входные данные, как из консоли, так и из окна Winforms.

0 Ответов