Alley Way
Alley Way

Reputation: 33

Run python script in VB.net on button click

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.

Upvotes: 3

Views: 5106

Answers (1)

FloatingKiwi
FloatingKiwi

Reputation: 4506

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

Upvotes: 2

Related Questions