python - 将 .txt 中的行读取到批处理文件中并作为参数传递到命令行?

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

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

在命令行中,它看起来像:“处理 c:/script.js 参数”。

我最初使用 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 来完成该任务。有没有办法使用批处理文件来做到这一点?

最佳答案

for /f "usebackq tokens=* delims=" %%# in ("C:\path\to\document.txt") do (
    call "C:/path/to/script.js" %%#
)

关于python - 将 .txt 中的行读取到批处理文件中并作为参数传递到命令行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30756633/

相关文章:

python - Matplotlib 线宽基于轴,而不是基于点

Python 正则表达式 - 使用大量匹配项匹配换行符

postgresql - 如何从 plpgsql 函数运行 bat 文件

windows - ForFiles 命令在 Windows 7 和 Windows 2008 Server 上返回不同的结果

windows - 批处理脚本打印将要执行的命令而不是执行

php - 将 CLI PHP 与 CakePHP 集成

java - 使用 Java 构建 Maven : How to execute script located in resources?

python - 跳转到 for 循环内 readlines 的下一行

c++ - 是否存在 C++ shell 框架?

php - 长时间运行的 php 脚本的内存注意事项