Link Visual Basic with Python

2019-07-29 04:13发布

i've been searching about how to link visual basic with python file

i've tried so hard through using shell in Visual Basic but nothing happend

i have python file called Go.py and i want to link Visual Basic button with it and get the return into variable

any idea ?

1条回答
成全新的幸福
2楼-- · 2019-07-29 05:07

First, you can use Shell, although it's unfortunately probably more complicated than you imagined.

Your current problem is a simple one - Shell can't run a python file directly, so you need to have Shell call cmd /c python.exe Go.py, and you may need to provide a full path to python.exe as well.

However, you also want to capture the result, and Shell only returns the process ID, not any kind of process output. You can check out some examples of external process invocation, although they don't explicitly cover how to capture output. If Go.py outputs to the terminal, you can probably capture the output into a file using standard Windows output redirection, and then open the file in VisualBasic and read the values.

You can also use System.Diagnostics.Process() instead of jumping through all the hoops of trying to get more functionality out of Shell. (Specifically, review the ProcessStartInfo class properties related to output redirection which give you much more control than anything using Shell will).

查看更多
登录 后发表回答