zoukankan      html  css  js  c++  java
  • 关于通过linux访问windows执行windows环境下的Python文件的相关操作。

    今天有个需求需要将linux和windows 进行打通,然后执行windows上面的python文件。

    我们是通过Python执行调用执行windows上面的东西,windows上面也是Python文件。

    具体参考:https://blog.csdn.net/Together_CZ/article/details/86623977#comments_12356187

    这里值得注意的是,我们从linux向windows发送指令的时候,我们一定要能从linux ping的通我们本地的windows服务器。

    如果ping 不同的话会出现下面这个错误:

    Connection to 10.0.3.129 timed out. (connect timeout=30)')

    如果你服务器能ping的通的话可能还会出现下面这个问题。

    winrm.exceptions.InvalidCredentialsError: the specified credentials were rejected by the server

    这个问题参考这个链接:https://www.jianshu.com/p/e473fbdf9854

    我运行的代码如下:

    #!/usr/bin/python
    # coding:utf-8
    from winrm.protocol import Protocol
    
    p = Protocol(
        endpoint='http://10.0.3.123:5985/wsman',
        transport='ntlm',
        username=r'用户名',
        password='gxg123456',
        server_cert_validation='ignore')
    shell_id = p.open_shell()
    command_id = p.run_command(shell_id, b'python F:/softinstall/Python/pythonworkplace/test.py', ['/all'])
    std_out, std_err, status_code = p.get_command_output(shell_id, command_id)
    p.cleanup_command(shell_id, command_id)
    print(std_out, status_code)
    p.close_shell(shell_id)

    执行出来的结果如下:

     这样我们在linux服务器上面 就能远程执行我们windows上面的程序。至此问题得到解决。

  • 相关阅读:
    CRB and His Birthday(2015多校)
    B. Bear and Three Musketeers
    Uva657
    cas服务端改造
    有用的maven插件
    maven管理的非标准目录
    struts2中的action交由spring管理
    数据库分库
    linux内核系列之二_资源
    linux内核系列之一_工具
  • 原文地址:https://www.cnblogs.com/gxgd/p/12980759.html
Copyright © 2011-2022 走看看