Utilize a command in batch to change the Output language of the CMD - batch-file

I wrote a batch script and everything ran fine, however I encountered problems when I transfered the script to another computer which uses the cmd in english and I no longer could utilize the script as it looked for specific words in the german cmd output.
I currently have it set to english, and I was trying to figure out if there was a way for me to use a command which can be added at the beginning of a batch script to either check the language and change it or just ultimately change it.
On google I found something about "chcp" but that didnt seem to help either. If anyone knows of anyway to solve my problem I deeply thank you.
P.S. I am trying to change it to german if that helps.
https://github.com/Pedrov01/PingsCommandOrganiser
Feel free to ask any questions if needed!
-Kind regards

It's not possible to change the language if the other language is not installed. So you have to write your code language-independent. The following takes advantage that the hostname is immediately followed by the IPaddress (not sure if it's the same in all languages (although I guess it is) - tested with German and English):
language dependent text HOSTNAME [IPADDRESS] language dependent text
Code:
#ECHO OFF
setlocal
set /p "destination=Enter destination: "
for /f "delims=" %%i in ('ping -4 -n 1 %destination% ^|find "["') do (
for %%j in (%%i) do (
echo %%j|find "[" >nul && (set "_ip=%%j" & goto :continue )
set "_name=%%j"
)
)
:continue
set _ip=%_ip:~1,-1%
set _

Related

hostname result as variable and then comparing it

So. This is making me go crazy. My batch file knowledge is very basic.
So far I have this from other sources to set a variable to be the result from hostname
FOR /F "usebackq" %%i IN (`hostname`) DO SET PCNAME=%%i
I'm still confused by this whole line but it works so I've kept it. I would like to understand what each part of it is doing though.
With that variable PCNAME I now want to do the following
IF PCNAME = RDS then GOTO exit
else
GOTO main
But I can't get this IF ELSE part to work (the above I know isn't true code but it's just to explain what I'd like to do).
So to sum up.
Create a variable from the result of hostname.
Compare that variable to see if it matches RDS. If it does, then quit, if it doesn't go onto another part of the batch file.
I was thinking of looking to see if its easier to do in Powershell instead. My knowledge of that is mega basic as well but looks like Powershell is easier to use than batch files.
Thanks for the replies. In the morning, and as Gerhard Barnard mentioned I realised I could just use %computername% which works
#echo off
IF %computername% EQU MyPC (
echo MyPC
) else (
echo Do nothing
)

How to turn multiple parameters into a single parameter in Batch?

This topic is really hard to explain, so try to understand it. I'm working on a project called RoSOX that uses a URI to join a server (on another end)
However, this batch program requires at least 3 parameters. If you were to run it under the Windows Command Prompt, you would run it like this RoSOXLauncher.bat "IPHere" "PortHere" "UsernameHere". This is the code that obtains those values (Not the entire program though)
#echo off
set ip=%~1
set port=%~2
set username=%~3
Unfortunately, I found another post mentioning that URI Protocols (aka Registry Entries that allow starting a program from your web browser, such as "mailto:example#example.com") only accept 1 parameter regardless of the program. My theory to bypass this is to have the input connected by commas so it's considered one parameter. It would be written like this: RoSOXLauncher.bat IPHere,PortHere,UsernameHere An example would be this. The logarithm would be
Disassemble the values from the commas (The FOR command is probably used)
Take each value and put it into its own variable
Continue the rest of the script
Does anyone know how this logarithm would be wrote in Batch? This is the only thing preventing me from having my program run correctly.
It seems very unclear as to what you want, but if I understand your requirement correctly then:
#echo off
set ip=%~1
set port=%~2
set username=%~3
Will still work if you do:
RoSOXLauncher.bat IPHere,PortHere,UsernameHere
Simply because the delimiters excepted are whitespace, comma and semicolon. You can try this and see for yourself.
RoSOXLauncher.bat IPHere;PortHere;UsernameHere
RoSOXLauncher.bat IPHere PortHere UsernameHere
Will do the same.
On the other hand, your program which you send the parameters from might also delimit by whitespace, command or semicolon, then you might simply use aother common delimiter like - or : see this:
#echo off
for /f "tokens=1-3 delims=-" %%i in ("%~1") do (
echo ip %%i
echo port %%j
echo username %%k
)
Which you can run using:
RoSOXLauncher.bat IPHere-PortHere-UsernameHere
or
#echo off
for /f "tokens=1-3 delims=:" %%i in ("%~1") do (
echo ip %%i
echo port %%j
echo username %%k
)
which you can run with:
RoSOXLauncher.bat IPHere:PortHere:UsernameHere

Batch commands for rds

I have a project for my Radio Station where I copy the text within a .wsx file of what is on air and parse it to a Audio Processor in my private network for RDS Display using a wget command like
set /p TEXTO= 0<R:\40.wsx
wget -q "http://x.x.x.x:7380/parameter/fm/rds/rds_rt=%TEXTO%" -O NUL
It works great but it won't filter if it's music or promotions.
My challenge is to be able to filter and only parse music names.
For the process I marked the Files that i don't want to show up like commercial, or promotions to start with a "#-" without the quotes.
So the text will show like #-Promo1
My Code:
for /F "delims=" %%a in ('FINDSTR "\<#-.*" C:\RDS\PRUEBAS\txt1.wsx') do set
"VAR=%%a"
echo %VAR%
if "%VAR%" == "true" (
set /p VAR=0<C:\FILEPATH\LOS40.wsx & wget -q
"http://x.x.x.x:7380/parameter/fm/rds/rds_rt=%VAR%" -O NUL
) else (
set /p TEXTO=0<C:\FILEPATH\ENVIVO.wsx & wget -q
"http://x.x.x.x:7380/parameter/fm/rds/rds_rt=%TEXTO%" -O NUL
)
I can't seem to find a correct way to filter it.
pls Heelpp..
for /F "delims=" %%a in ('FINDSTR "\<#-.*" C:\RDS\PRUEBAS\txt1.wsx') do set
should be
for /F "delims=" %%a in ('FINDSTR /b "#-" C:\RDS\PRUEBAS\txt1.wsx') do set
to find those lines in the .wsx file that do /b begin with "#-"
If you want to find those lines that do not begin with "#-" then add /v to the /b.
The result will be a line from the file which does [not] begin with "#-" which will be placed in %%a.
If you simply assign %%a to a variable as you are doing, that variable will contain after the for the last value that was assigned to it.
If you want to execute your wget on each name, then use
for /F "delims=" %%a in ('FINDSTR /B "#-" C:\RDS\PRUEBAS\txt1.wsx') do (
echo %%a
)
and between the parentheses you can execute commands using %%a as a filename.
Quite what you propose to do is obscure. I've no idea what the set/p from an unexplained file is meant to do, but be aware that any code between parentheses is subject to the delayedexpansion trap - please explain what processing you intend to apply to the filenames that do[not] match a leading #-.
You should read SO items on delayed expansion (it's documented with and without the space) to understand the problems with and solutions to processing values that are altered within a loop.
First of all thanks for your help.. I don't have experience in coding.
Let me explain a little bit more..
As I said before its a radio station which will provide text to the Car o home stereos using the RDS Protocol which allow me to send text like song name, title, etc.
Im My case the Audio Processor that let me send the text will receive the info as a URL where I add at the end the text I want to send.
For Example:
http://x.x.x.x:7380/parameter/fm/rds/rds_rt=%TEXTO%
%TEXTO% will be the text Im sending.
C:\RDS\PRUEBAS\txt1.wsx Contains the text of what it being played at the moment and which is being read to see if the #- for the script to avoid sending those titles.
I have a Pc running a Directory Monitor Program that will monitor events on file C:\RDS\PRUEBAS\txt1.wsx and that as soon as being modified, it will execute the batch file CHECKRDS.cmd.
After testing I decided to run a code in CHECKRDS.cmd like:
for /F "delims=" %%a in ('FINDSTR /v "#-" R:\40PPALES.wsx') do (
START "" RDS.bat
)
EXIT
RDS.bat contains code and it works fine:
set /p TEXTO= 0<C:\RDS\PRUEBAS\txt1.wsx
wget -q "http://x.x.x.x:7380/parameter/fm/rds/rds_rt=%TEXTO%" -O NUL
EXIT
As far as the set /p I test it from What does /p mean in set /p?
AS I said before Im new at coding and I just googled everything and started to assable the pieces of the puzzle.
Pls, If you think I should be doing these process diferently, pls let me know..
And sorry for my bad english..
regards

How to find string that contains commands in batch

stackoverflow.
I've been working on a major project in batch recently for a friend of mine.
I know that there are better ways to do this, but i just wanted to challenge batch coding :)
So, here's my issue:
I want to be able to find a string called:
if "%MORELISTINPUT%"=="%COUNTER2%" goto blablatest2
now here comes the challenge, i've used this code so far:
#ECHO OFF
(
FOR /F "tokens=*" %%A IN (moreserver.bat) DO (
ECHO %%A
IF "%%A" EQU "if "%MORELISTINPUT%"=="%COUNTER2%" goto blablatest2" (
echo if "%%MORELISTINPUT%%"=="%%COUNTER2%%" goto %NEWNAME%
)
)
) >moreserverout.txt
pause
But it just wont find the text. (I'm thinking it's due to commands and variables, but i'm not sure)
I've tried adding %'s around the variables, added ^'s before commands and also variables and it just wont work.
How would i go about using the string containing both commands and variables as plain text?
Thanks in advance!
~Niklas
edit: Here's links to my "project files"
Doesn't work for me tho, sorry ^^
I'm calling this small program from within a bigger program, and when i'm running this it just displays a line saying
%%MORELISTINPUT%%"=="%%COUNTER2%%" goto %NEWNAME%
between every line. (it lists all lines in the moreserver.bat file in the cmd window)
Here's a link to the complete files:
http://pastebin.com/u/MinervaXcel
The top 4 ones named "WoW Client Config" are the ones that are used.
"Main" is as said the main one. "Chooseserver.bat" is the one that's containing the code in question! :)
use
IF "%%A" EQU "if "%%MORELISTINPUT%%"=="%%COUNTER2%%" goto blablatest2" (
as you did on the following line (worked for me)

Batch Command to replace text in file

I know this question is asked many times, but I didn't get the answer for what I am searching.
I want to replace a pattern using windows .bat file.
I know how to replace X with Y.
But I am trying to replace say installPath with C:\Programfiles\Install\.
Here, I am facing issues as the new value string contains \ i.e special character.
Please let me know how I can replace this.
This works fine for me
set p=installPath
set p=%p:installPath=C:\Programfiles\Install\%
echo %p%
Followinf script will find the string in the file and replace with another string.
EX. "installPath" will be replaced with "C:\Programfiles\Install"
#echo off
for /f "usebackq tokens=*" %%a in ("test.txt") do call :Replace "%%a"
del "test.txt"
rename "newfile.txt" test.txt
exit /b
:Replace
set str1=%~1
set str1=%str1:installPath=C:\Programfiles\Install%
echo.%str1%>>"newfile.txt"
exit /b
Perhaps this tool might help you:
http://sourceforge.net/projects/fart-it/
This should work... By the way, this is my first post on this website.
The following uses delayed expansion so that you have two different 'variable symbols' to play with:
setlocal enabledelayedexpansion
set iPath=installPath
set input=C:\Programfiles\Install\
set p=!iPath:installPath=%input%!
Hope this helps

Resources