如何将VB.NET程序与Python连接
我有一个用Python写的“Hello, World”程序。这个程序会接收用户的输入,然后打印出“Hello”和用户输入的内容。
>>> Name: Kent
Hello, Kent.
另外,我还有一个用VB.NET写的程序。这个程序里只有一个文本框1、一个文本框2和一个按钮。
我想要的是,当用户在VB.NET应用的文本框1里输入他们的名字,然后点击按钮;
我希望这个VB.NET应用能够调用Python脚本,把文本框1里的内容传进去,并把Python脚本的输出结果显示到VB.NET应用的文本框2里。
我该怎么做呢?
1 个回答
0
这段话是从MSDN网站上的C#内容翻译过来的。显然,你会用Python解释器来代替Perl(我个人不使用Python,但原理是一样的)。
Sub ScriptToVB(ByVal arguments As String)
Dim p As System.Diagnostics.Process = New System.Diagnostics.Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.FileName = "perl.exe"
p.StartInfo.Arguments = "C:\Users\me\Desktop\toSendToVB.pl " & arguments
p.Start()
Dim output As String = p.StandardOutput.ReadToEnd()
mySecondTextBox.Text = output
End Sub