python调用cmd执行命令_python3 自动执行windows命令行cmd

import subprocess

import time

# import optparse

# parse = optparse.OptionParser(usage='"usage:%prog [options] arg1,arg2"', version="%prog 5.0")

# parse.add_option('-f', '--file', dest='file', action='store', type=str, metavar='file', help='请输入配置文件地址')

# options, args = parse.parse_args()

# cmd = ["test.py","-f","info2 \n"]

# subprocess.call(cmd,shell=True)

# time.sleep(1)

# subprocess.call("test.py -f infotest ",shell=True)

file = input("请输入配置文件(如:auto.txt):")

file = file if file!="" else "auto.txt" # 默认 auto.txt

with open(file,"r",encoding="utf-8") as f:

cmd_content = f.read()

for cmd in cmd_content.split("\n"):

cmd_shell = cmd.split(",")

print("cmd run:%s" % " ".join(cmd_shell))

subprocess.call(cmd_shell, shell=True)

print(".1秒后执行下一个任务")

time.sleep(.1)

input("auto run success")

如果本文对您有所帮助,请支持下本站哦!!!^_^

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值