单击按钮在VB.net中运行python脚本 [英] Run python script in VB.net on button click

查看:165
本文介绍了单击按钮在VB.net中运行python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在VB.Net中单击按钮时在cmd中运行Python脚本。
是否需要在批处理文件中调用Python脚本?还是可以直接在VB中完成?

I want to run a Python script in cmd when a button is clicked in VB.Net. Do you need to call the Python script in a batch file? Or can you do it directly in VB?

我尝试过

Dim ps As New ProcessStartInfo("cmd.exe")
    ps.Arguments = "C:\yourbatfile.bat"
    Process.Start(ps)

但这只会打开cmd窗口,不会执行bat文件。

But that only opens the cmd window and doesn't execute the bat file.

推荐答案

Dim psi = New ProcessStartInfo("c:\python27\python.exe", "myPythonScript.py")
Dim proc = Process.Start(psi)
proc.WaitForExit()
If proc.ExitCode <> 0 then throw new Exception(" Script Failed")

这篇关于单击按钮在VB.net中运行python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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