问题描述
我有一个在后台运行python的进程,以便接收输入和输出。 我的程序可以有多个输出,但只能输入一个,否则程序将冻结。如果python.exe要为新用户输入使用不同的值,我该怎么做?
VB.net
Public Value As String
Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click 'Works on button
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()
AddHandler p.OutputDataReceived,AddressOf process_OutputDataReceived
p.StandardInput.WriteLine(TextBox2.Text)
p.StandardInput.WriteLine(TextBox2.Text) 'Freezes with this input added. Only works with one use input
p.BeginoutputReadLine()
SimpleEditor1.Text = Value
p.WaitForExit()
End Sub
Public Sub process_OutputDataReceived(ByVal sender As Object,ByVal e As DataReceivedEventArgs)
On Error Resume Next
If e.Data = "" Then
Else
Value += ">" + e.Data + Environment.NewLine
End If
End Sub
我正在尝试做的Python代码
print("bye")
print("Hello")
i = int(input("Enter num:"))#RUNS WHEN THERE IS ONLY THIS INPUT
print(i+1)
q = int(input("Enter num:"))#FREEZES WHEN THIS IS IN THE PYTHON FILE
print(q+5)
感谢您的帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)