3
votes

Well, I have a "Hello, World" program written in Python. This program takes the user input and prints out "Hello" along with the user input.

>>> Name: Kent
Hello, Kent.

On the other hand, I have a program written in VB.NET. It consists of only a textbox1, a textbox2 and a button.

What I want is that, when the user inputs his/her name in the textbox1 of the VB.NET application and clicks the button;

I want this VB.NET application to access the python script, input the text from the textbox1 and display the output result from the Python script into the textbox2 of the VB.NET application.

Algorithm of how I want the VB.NET program to work.

How do I do it?

1
Any particular reason you've tagged this ASP.NET? Any particular reason you're mixing Python with .NET (why not just use IronPython)? And the .NET class responsible for interacting with other processes is System.Diagnostics.Process - mason
I am sorry for tagging ASP.NET, anyways, using system.diagnostics.process.start(filepath) will only open the python application. But wont do the next necessary steps. - kent hamlin
Pass it as an argument. Probably not a good idea to do an interactive shell. - mason

1 Answers

0
votes

Translated from the original C# off the MSDN website. Obviously, you are going to use your python interpreter versus Perl (I don't use Python, personally, but it's the same idea).

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