Reputation: 33
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
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