【问题标题】:Reading lines from .txt into batch file and handing into command line as arguments?将 .txt 中的行读入批处理文件并作为参数传递给命令行?
【发布时间】:2015-08-25 17:20:36
【问题描述】:

我需要逐行读取 .txt 文件的每一行,将每一行作为参数传递给我在 CMD 行界面中运行的进程。

在命令行中它看起来像:“process c:/script.js arguments”。

我最初是用 Python 做的:

with open("C:\path\to\document.txt", "r") as fileOpen:
lines = fileOpen.read().split("\n")
for line in lines:
    subprocess.call("someProcess C:/path/to/script.js " + line, shell=True)

但是,由于需要在没有依赖关系的情况下进行分发,我现在宁愿不使用 python 来完成任务。有没有办法使用批处理文件来做到这一点?

【问题讨论】:

  • 您可以使用批处理脚本解析文本文件,检查它here,然后您可以像上面那样call.js 脚本

标签: python batch-file command-line-interface command-line-arguments


【解决方案1】:
for /f "usebackq tokens=* delims=" %%# in ("C:\path\to\document.txt") do (
    call "C:/path/to/script.js" %%#
)

?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 2012-12-21
    • 2023-03-11
    相关资源
    最近更新 更多