Remote execution with Python 2.6 (or higher)

Last edited on

Introduction

The standard Python module multiprocessing got introduced in Python 2.6 and makes creating simple client/server applications extremely easy.

Here is an example that shows how to execute arbitrary commands remotely. Because it allows executing arbitrary commands it is probably a good idea to not use it exactly like this, but rather to extend it to do only exactly what you want it to do (like kill one specific application or so).

You can download a package with the following files os_system_py-20130730-1347.zip (and an additional file squishpyutil.py.

Example - Using os_system_client.py in Squish test scripts

Prerequisites:

function main()
{
    output = OS.capture('python "' + squishinfo.testCase + '/../os_system_client.py" DIR');
    output = output.replace(/\r\n/g, "\n");
    output = output.replace(/\r/g, "\n");
    output = output.split("\n");
    for (var i = 0; i < output.length; i++) {
        test.log(output[i]);
    }
}
test.js

Example - Using os_system_client.py without Squish

Prerequisites:

Executed in cmd.exe:

C:\Users\MyUser\Desktop> python os_system_client.py DIR


Executing remotely: "DIR"


[...]

Please note that there are platform specific tools, like PsExec which may be an option if you can limit yourself to the platform(s) supported by them.