将Visual Basic与Python链接 [英] Link Visual Basic with Python

查看:100
本文介绍了将Visual Basic与Python链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找如何将Visual Basic与python文件链接

我通过在Visual Basic中使用 shell 进行了非常努力的尝试,但没有任何反应

我有一个名为 Go.py 的python文件,我想将Visual Basic按钮与之链接并返回到变量

有什么主意吗?

解决方案

首先,您可以使用 Shell ,尽管不幸的是,它可能比您想象的要复杂.

您当前的问题很简单- Shell 无法直接运行python文件,因此您需要让 Shell 调用 cmd/c python.exe Go.py ,并且您可能还需要提供 python.exe 的完整路径.

但是,您还希望捕获结果,并且 Shell 仅返回进程ID,而不返回任何类型的进程输出.您可以查看一些外部流程调用的示例,尽管它们没有明确介绍如何捕获输出.如果将 Go.py 输出到终端,则可以使用 System.Diagnostics.Process() 而不是试图从 Shell 中获得更多功能的过程.(具体来说,请查看 ProcessStartInfo 与输出重定向相关的类属性,与使用 Shell 进行的操作相比,该属性为您提供了更多的控制权.

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 ?

解决方案

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).

这篇关于将Visual Basic与Python链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆