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 -
Shell
can't run a python file directly, so you need to haveShell
callcmd /c python.exe Go.py
, and you may need to provide a full path topython.exe
as well.However, you also want to capture the result, and
Shell
only 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.py
outputs 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 theProcessStartInfo
class properties related to output redirection which give you much more control than anything usingShell
will).