Solved

Problem with FOR loop in Windows 7

Posted on 2014-04-11
2
382 Views
Last Modified: 2014-04-11
I have a very simple text file:
line1
line2
line3

and I am running this plain-vanilla command in a cmd window
FOR /F %i IN (textfile.txt) DO (echo okay)

This should echo the word "okay" three times. Instead it gives me absolutely nothing. Any ideas?
0
Comment
Question by:criskrit
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39994785
Open the file in Notepad and click "Save as"; somewhere (depending on the version) on the "Save as" page, it'll show the file's encoding. The file is probably saved as Unicode, which can't be interpreted directly by a "for /f" loop.
Either change the encoding to ANSI and save, or use the output of "type" in the loop:
FOR /F %i IN ('type textfile.txt') DO (echo okay)

Open in new window

0
 

Author Comment

by:criskrit
ID: 39994825
#@^&!&@*!(*@&^!@#%*!  --> censored to protect the innocent!

You are a genius!!!!! THANKS!!!!  :-) :-) :-) :-)
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You may have a outside contractor who comes in once a week or seasonal to do some work in your office but you only want to give him access to the programs and files he needs and keep privet all other documents and programs, can you do this on a loca…
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question