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

131 views Asked by At

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.

In the command line it would look like: "process c:/script.js arguments".

I originally did this using 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. Is there a way to do this using a batch file?

1

There are 1 answers

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

?