在网络上的另一台计算机上启动进程 [英] Start a process on another computer on the network

查看:68
本文介绍了在网络上的另一台计算机上启动进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要启动一系列python脚本和/或其他Windows可执行文件.其中一些需要Windows系统,另一些需要Linux机器.

I'm required to start a series of python scripts and/or other windows executables. Some of these require a Windows system, others require a Linux machine.

当前有指定的计算机来运行与OS相关的程序.所以我知道我要在哪里启动哪个程序.

Currently there are designated machines to run the OS-dependent programs. So I know where I want to start which program.

有没有一种方法可以从本地网络上另一台计算机上的python脚本启动python脚本(或Windows可执行文件)(例如,运行 192.168.0.101:/dir/python_script_123.py >?

Is there a way to start a python script (or a windows executable) from a python script, on the local network, on another computer (e.g. run 192.168.0.101:/dir/python_script_123.py?

随后应运行各种程序的脚本可能会在伪代码中看起来像这样.

The script, which should then run various programs may then look something like this in pseudo code..

linuxip = 192.168.0.101
linuxparam = "required parameter"

winip = 192.168.0.201
winparam = "required parameter"

#option 1 (run all), 2(run linux only), 3(run windows only), 4(run local only)
option = 1

if option == 1:
    magic_things.run("linuxip:/dir/linux_script.py" + linuxparam)
    magic_things.run("winip:C:\\dir\\windows_prog.exe" + winparam)
    subprocess.call(["/dir/local_script.py","parameter"])
    subprocess.call(["/dir/another_local_script.py","parameter"])
elif option ==2:
    [...]

推荐答案

您需要从客户端连接到服务器.如果是Linux计算机,则可以使用SSH.参见 http://en.wikipedia.org/wiki/Secure_Shell

You need to connect to your server machine from your client. In case of the linux machine you could use SSH. see http://en.wikipedia.org/wiki/Secure_Shell

假设您正在运行的linux服务器上有一个 ssh服务器,则可以使用paramiko软件包(

Assuming you have a ssh server on the linux server running you could use the package paramiko (http://docs.paramiko.org/en/1.15/api/client.html) to connect to the machine and run your script there.

这可能看起来像这样:

from paramiko.client import SSHClient

client = SSHClient()
client.load_system_host_keys()
client.connect('linuxip', username='your_user', password='very_secret')
stdin, stdout, stderr = client.exec_command('python /home/your_user/your/path/to/scripty.py')

但是请注意,将密码存储在脚本中并不是很安全,使用公用/专用密钥身份验证可能更好(请参阅Wiki文章).

However please note that it's not very secure to store passwords in scripts and it's probably better to use a public/private key authentication (See the wiki article).

paramiko软件包还提供了用于ssh服务器的选项,因此这可能是针对Windows机器的解决方案,但是我不太确定,因为我不再运行任何Windows机器.

The paramiko package also offers the option for an ssh server, so this might be a solution for your windows machine, but I am not very sure as I don't run any windows machines any more.

希望这很有帮助!

大卫

这篇关于在网络上的另一台计算机上启动进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆