V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2018-11-28 19:04:19 +08:00 · 7779 次点击
    这是一个创建于 1947 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近在学 python,其中有调用了 bat 命令文件,之间是怎么传参的呢
    10 条回复    2018-11-28 19:36:32 +08:00
    huangzhe8263
        1
    huangzhe8263  
       2018-11-28 19:11:04 +08:00
    如果是我想法可能是直接执行 shell 命令,subprocess.popen()
    itskingname
        2
    itskingname  
       2018-11-28 19:12:14 +08:00 via iPhone
    os.system("xxx.bat -arg1 -arg2")
    bypain
        3
    bypain  
    OP
       2018-11-28 19:13:33 +08:00
    @huangzhe8263 我目前是用这种方法,但是不知道 bat 文件里该如何接收参数
    bypain
        4
    bypain  
    OP
       2018-11-28 19:14:17 +08:00
    @itskingname 请问 bat 文件里该如何接收-arg1 -arg2 参数呢
    itskingname
        5
    itskingname  
       2018-11-28 19:16:02 +08:00
    @bypain #4 这就是你 bat 的问题了,就不是 Python 的问题了。
    huangzhe8263
        6
    huangzhe8263  
       2018-11-28 19:18:34 +08:00
    @bypain #3 ls +1 可能要去学习一下相关语法
    lanyusea
        7
    lanyusea  
       2018-11-28 19:23:00 +08:00
    %1 是第一个参数,
    %2 是第二个参数,
    以此类推

    %0 是 bat 脚本的名字我记得
    bypain
        8
    bypain  
    OP
       2018-11-28 19:36:09 +08:00
    @itskingname 好的 非常感谢
    bypain
        9
    bypain  
    OP
       2018-11-28 19:36:14 +08:00
    @huangzhe8263 好的 非常感谢
    bypain
        10
    bypain  
    OP
       2018-11-28 19:36:32 +08:00
    @lanyusea 谢谢,可以了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3250 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:17 · PVG 22:17 · LAX 07:17 · JFK 10:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.