我正在寻找一个python / batch脚本的例子:
我认为解决方案取决于某种特殊的python库?
如果进程以批处理而不是python方式启动,那么组合python / batch的任务会更容易吗(这会是一种更常见的解决方案)吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
代码示例:
import subprocess
bat_text = "dir" # (text to write in bat file)
bat_file = open("program.bat","w") # (open file in write mode)
bat_file.write(bat_text) # (write bat_text on bat_file)
bat_file.close() # (close file)
command = "C:\program.bat" # (the location of bat file)
execute = subprocess.Popen(command, stdout=subprocess.PIPE) # (exec the command)
output = execute.stdout.read() # (read output)
print output # (print output)
子流程教程