简体   繁体   English

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

[英]Reading lines from .txt into batch file and handing into command line as arguments?

I need to read each line of a .txt file, line by line, handing in each line as an argument to a process I'm running in the CMD line interface. 我需要逐行阅读.txt文件的每一行,并将每一行作为我在CMD行界面中运行的进程的参数来提交。

In the command line it would look like: "process c:/script.js arguments". 在命令行中,它看起来像:“处理c:/script.js参数”。

I originally did this using Python: 我最初是使用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)

However due to the need to distribute without dependencies I would now rather not use python for the task. 但是由于需要分发而没有依赖项,我现在宁愿不使用python来完成任务。 Is there a way to do this using a batch file? 有没有办法使用批处理文件来做到这一点?

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

?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM