推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
fangazio
V2EX  ›  Python

python 调用 cmd 命令问题

  •  
  •   fangazio · Dec 11, 2015 · 3837 views
    This topic created in 3942 days ago, the information mentioned may be changed or developed.

    实现远程关闭计算机的功能
    直接在电脑上输入指令 shutdown /m \192.168.1.211 /s /t 1 没问题
    然后用 python 调用就无法实现功能
    import os
    os.system('shutdown /m \192.168.1.211 /s /t 1')
    运行无法实现功能
    求解

    6 replies  •  2015-12-11 20:31:35 +08:00
    kmahyyg
        1
    kmahyyg  
       Dec 11, 2015
    考虑把单引号换成双引号试试
    jpyl0423
        2
    jpyl0423  
       Dec 11, 2015
    \ 需要转义
    chinuno
        3
    chinuno  
       Dec 11, 2015
    建议调用系统命令特别是 Windows 的还是字符串前面加 r 吧。一个一个处理转义麻烦费时间还容易出错
    fangazio
        4
    fangazio  
    OP
       Dec 11, 2015
    @chinuno 你的是对的,加 r 谢谢
    skylancer
        5
    skylancer  
       Dec 11, 2015
    为什么要用 /作为参数的用法而不用-呢
    shutdown -s 和 shutdown /s 也是等价的啊
    ifaii
        6
    ifaii  
       Dec 11, 2015
    把 '\' 换成 '/' 或者前面加 r
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2573 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 11:48 · PVG 19:48 · LAX 04:48 · JFK 07:48
    ♥ Do have faith in what you're doing.