i’ve been searching about how to link visual basic with python file
i’ve tried so hard through using shell in Visual Basic but nothing happend
i have python file called Go.py and i want to link Visual Basic button with it and get the return into variable
any idea ?
First, you can use
Shell, although it’s unfortunately probably more complicated than you imagined.Your current problem is a simple one –
Shellcan’t run a python file directly, so you need to haveShellcallcmd /c python.exe Go.py, and you may need to provide a full path topython.exeas well.However, you also want to capture the result, and
Shellonly returns the process ID, not any kind of process output. You can check out some examples of external process invocation, although they don’t explicitly cover how to capture output. IfGo.pyoutputs to the terminal, you can probably capture the output into a file using standard Windows output redirection, and then open the file in VisualBasic and read the values.You can also use
System.Diagnostics.Process()instead of jumping through all the hoops of trying to get more functionality out ofShell. (Specifically, review theProcessStartInfoclass properties related to output redirection which give you much more control than anything usingShellwill).