Solved

Problem with FOR loop in Windows 7

Posted on 2014-04-11
2
376 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 83

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
On some Windows 7 (SP1) computers, Windows Update becomes super slow even the computer is reasonably fast.  There's one solution that seemed to have worked well for me (after trying a few other suggested solutions).
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.

774 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