Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run python script in VB.net on button click

Tags:

python

vb.net

cmd

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?

I tried this

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

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

like image 210
Alley Way Avatar asked Jan 29 '26 15:01

Alley Way


1 Answers

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")
like image 178
FloatingKiwi Avatar answered Jan 31 '26 04:01

FloatingKiwi