I have been trying for 2 days to get the superficially-simple script below working:
for /F "eol=*" %%A in (c:/users/SCTMP000/server.txt) do (echo %%A)
This itself is a reduction of my desired code, which I intended to scroll through the above text file, which is just a list of domains, in order to issue a PING
/ TRACERT
command against each domain and pipe the output to another text file. But even this simple one-liner won't process the file.
I've seen countless variations of the above cited on MSDN, StackOverflow, this site and many personal developer blogs, so feel that I'm in the right ball-park, but mine won't work ! Depending on how I render the file-name and its path (-ie quoteless, wrapped in single-quotes, wrapped in double-quotes), I see:
[quoteless] - nothing: no file open activity, and therefore no ECHO per line
[double-quoted] - the full path-name ECHOed, ie c:/users/SCTMP000/server.txt
[single-quoted] - the complete file actually opens in NotePad !!
So the path is correct, but neither the script run as a batch file, nor a command run interactively, seems to be able to actually open the text file and scroll through it. Note also that I have tried a number of the line-options: DELIMS, TOKENS, EOL etc, without success.
What am I doing wrong ? Thanks in advance.
for /f
in DOS. cmd and DOS are completely different thingsExplorer
orNotepad
can access the file but yourCMD
instance can't? I suggest you try to isolate the problem: move the file elsewhere, create a new file with the same name in its place, try a different file in a different place altogether - see what works and what doesn't and use that to infer where the problem lies (e.g. the file, the path, the containing folder, ...).FOR
loop would print nothing butNotepad
would be able to open the file just fine (it might show a space or something at the beginning, but it'll open it all the same).