简体   繁体   中英

Execute python script on remote server via VB.Net and return result to local machine

The problem is the following: My local machine (computer A) runs VB.Net code locally. I need to run a Python script on another remote machine (computer B, the Python script resides on computer B) and get the result back to computer A , preferrably without having the Python script on computer B writing the output to a .csv file (or similar) and computer A then reading that file. That is, I would like to accomplish pretty much the following:

(VB.Net code on computer A)

matrixResult = getMatrixFromPython(args)

where the function getMatrixFromPython "invokes" the Python script on computer B and returns the matrix that script produces. My current solution is using WMI to execute a .bat file on the remote machine, and that .bat file in turn runs the Python script. This, however, leaves the problem of getting the result back to the VB.Net code on computer A.

Any help greatly appreciated. Thank you.

You could do this a number of ways.

  1. You could implement a WCF service in VB.net that executes the python script and passes the result back to the caller

    a. The python execution might also be easier to interact with if you use ironpython to run it directly rather than relying on capturing output from process.start and then interpreting it back into a data structure (although if you had to go that route then I'd suggest using JSON as there are libraries in .net and python that will read/write this format)

  2. Use powershell remoting to perform the remote execution, this will make it much simpler than with wmi to capture the output. Issues with this might be that it's not installed/configured everywhere it needs to be

  3. Convert the python script to run as a CGI script and run it from a web server. This means that calling it and getting outputis as simple as fetching a URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM