Saved Bookmarks
| 1. |
Solve : 2 question: for loop and accented letters? |
|
Answer» HELLO evryone, this is KiTiK, i'm new here. And I'm new in batch scripting. I read how for loop works both typing for /? in dos and in the article on this site. But I still have some problem to get it entirely. My purpose is to check if the COMMAND tasklist exist, and to do it i wrote this code: Code: [Select]for /f "tokens=1,* delims=;" %%a in ("%PATH%") do ( if exist %%a\tasklist.exe (echo there is) else (echo there is not) )this is good if the first entry in %path% is the system32 folder but i would like to check also in the other entries, but i connot understand how to do it without knowing the number of entries. Could you help me to understand it? It's puzzleing me Another simple question: how can my bat echo accented letters (è, ò, ù) properly? I didn't find a solution searching in GOOGLE. Thanks in advance and sorry for my bad English Quote this is good if the first entry in %path% is the system32 folder but i would like to check also in the other entries, but i connot understand how to do it without knowing the number of entries. The is no need to know the number of entries in the path. You can use the $Path notation which will search the entire path until a match is found: Code: [Select]echo off for %%a in (tasklist.exe) do if not "%%~$PATH:a"=="" echo %%~$PATH:a ) $Path will only search until a match is found. If you have multiple copies of a program, the snippet will echo only the first to the console. Quote Another simple question: how can my bat echo accented letters (è, ò, ù) properly? I didn't find a solution searching in google. Not to familiar with this, but I think you can use the chcp command. Good luck. really nice! I thought I should use $Path, but I put it in the wrong place, after the "IN". Thanks, even if I'd like to ask you some explanation about the for loop, I use it in C programming, but it seems so different... I can not get it's logic, could you tell me something about it, please? About the second question I think I'll use this notation: e', o', u' Quote from: SIDEWINDER on March 12, 2010, 08:57:33 AM
To echo accented characters the command ENVIRONMENT needs to be using a "codepage" which has them in its character set. For the characters which you find in French and Spanish I use code page 1252 which you can select by chcp 1252 at the prompt. The code page you are currently in can be seen by typing chcp without a number. Thanks for the tip Salmon Trout, but I tried it and I still get this symbol: þ instead of è. Perhaps I have to specify something else in the echo command, but what? Anyway thank you very much Quote from: KiTiK on March 12, 2010, 02:13:36 PM Thanks for the tip Salmon Trout, but I tried it and I still get this symbol: þ instead of è. what do you see when you type chcp at the prompt? before i used chcp 1252 it was 850There's a different solution to what sidewinder is getting at, without changing any settings. Open up MS-Word, put in your special characters, and click file > save. In the save menu, select Plain Text format (the one that says .txt). Then make sure the encoding is set to MS-DOS. If any letters are red, then they can't be used that way. Quote from: Helpmeh on March 12, 2010, 03:42:16 PM There's a different solution to what sidewinder is getting at, without changing any settings.Thanks Helpmeh, I did it and I noticed that mu special characters changes after I saved in that way. So, I guess, this is the problem. I wonder how and why the same special characters are well echoed for example in the for /? command... Is there a way to print characters with their ascii code, perhaps? I don't know. If this is possible this could solve another my problem I didn't speak about yet Anyway, thanks for helping meI was able to paste è,ò, and ù into command prompt without changing anything... Quote from: BC_Programmer on March 16, 2010, 09:04:14 AM I was able to paste è,ò, and ù into command prompt without changing anything... Code: [Select]C:\Windows\system32>chcp Active code page: 850 C:\Windows\system32>echo Nuages en début de journée Nuages en début de journée |
|