Select to view content in your preferred language

Halt/wait VB.net processing until Python script is complete.

2685
2
11-26-2014 09:57 AM
DaleShearer
Frequent Contributor

Thanks for looking at my issue.  I am calling a Python script with arguments from my VB.Net application.  What I want to do is have the VB.net application wait on the Python script to complete before it continues processing.

I am currently starting the Python script like this:

Dim A1 As String = "ExcelFile.xlsx"

Dim A2 As String = "DbfFile.dbf"

Shell("C:\Python27\arcGIS10.2\python.exe C:\PythonScripts\ExceltoDBF.py " + A1 + " " + A2)

It works fine.

I am trying the following code, from what I have found the structure of the exe and arguments are correct(maybe-maybe not?).  What occurs is the executable does work as the black window opens then immediately closes.

Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("C:\Python27\arcGIS10.2\python.exe", "C:\PythonScripts\ExceltoDBF.py " + A1 + " " + A2)

procStartInfo.RedirectStandardOutput = True

procStartInfo.UseShellExecute = True

procStartInfo.CreateNoWindow = False

Dim proc As New System.Diagnostics.Process()

proc.StartInfo = ProcStartInfo

proc.Start()

proc.WaitForExit()

Any ideas, do I have the code structure right?

Thanks for your time, Dale

0 Kudos
2 Replies
DaleShearer
Frequent Contributor

Well that was not too hard to fix, in a couple of lines of code that I was alternating between, in one line I had a space between "Python" and "Scripts": C:\Python Scripts\ExceltoDBF.py

 

Once I removed the space it worked fine:  C:\PythonScripts\ExceltoDBF.py

0 Kudos
curtvprice
MVP Alum

Why aren't you using the Wait property of the Shell function? Seems like that would be less trouble...

Shell Function

0 Kudos