推荐学习书目
› 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
bypain
V2EX  ›  Python

Python 调用 bat 文件,请问怎么传参

  •  
  •   bypain · Nov 28, 2018 · 8571 views
    This topic created in 2862 days ago, the information mentioned may be changed or developed.
    最近在学 python,其中有调用了 bat 命令文件,之间是怎么传参的呢
    10 replies  •  2018-11-28 19:36:32 +08:00
    huangzhe8263
        1
    huangzhe8263  
       Nov 28, 2018
    如果是我想法可能是直接执行 shell 命令,subprocess.popen()
    itskingname
        2
    itskingname  
       Nov 28, 2018 via iPhone
    os.system("xxx.bat -arg1 -arg2")
    bypain
        3
    bypain  
    OP
       Nov 28, 2018
    @huangzhe8263 我目前是用这种方法,但是不知道 bat 文件里该如何接收参数
    bypain
        4
    bypain  
    OP
       Nov 28, 2018
    @itskingname 请问 bat 文件里该如何接收-arg1 -arg2 参数呢
    itskingname
        5
    itskingname  
       Nov 28, 2018
    @bypain #4 这就是你 bat 的问题了,就不是 Python 的问题了。
    huangzhe8263
        6
    huangzhe8263  
       Nov 28, 2018
    @bypain #3 ls +1 可能要去学习一下相关语法
    lanyusea
        7
    lanyusea  
       Nov 28, 2018
    %1 是第一个参数,
    %2 是第二个参数,
    以此类推

    %0 是 bat 脚本的名字我记得
    bypain
        8
    bypain  
    OP
       Nov 28, 2018
    @itskingname 好的 非常感谢
    bypain
        9
    bypain  
    OP
       Nov 28, 2018
    @huangzhe8263 好的 非常感谢
    bypain
        10
    bypain  
    OP
       Nov 28, 2018
    @lanyusea 谢谢,可以了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4689 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 07:18 · PVG 15:18 · LAX 00:18 · JFK 03:18
    ♥ Do have faith in what you're doing.