Solved Batch Help Needed

December 4, 2011 at 05:06:05
Specs: N/A
Hi, i am new at this (batching) please help.

How do i make a batch file echo different variables to a single line text file?
eg. The file checks for a var...If the condidtion is met it echoes y then e then s all in different lines of the batch file, I want them to be on the same line in the text file the are echoed to makeing the word 'yes'. Is this possible?

eg.
@echo off
set /p userinput=
IF %userinput%==hello goto yes
IF NOT %userinput%==hello goto no

:yes
echo y>>Test.txt
echo e>>Test.txt
echo s>>Test.txt

:no
cls
exit

This is the result
Test.txt - Notepad
-----------------------------
y
e
s

This is the result I want
Test.txt - Notepad
------------------------------
y e s or yes


IS THIS POSSIBLE? IF Yes please help!


See More: Batch Help Needed

Report •


#1
December 4, 2011 at 07:26:22
✔ Best Answer
Just put
Echo Yes >> Test.txt
To put the word Yes into a text file on one line.

If you wanted to do this with variables you would have your variables set first like;
SET var1=Y
SET var2=E
SET var3=S

Then you would put
Echo %var1%%var2%%var3% >> Test.txt

So for example. To get user input then Echo it to a text file. You would use this.

@ECHO OFF
Echo Enter something
SET /p "userinput=>"
Echo %userinput%>> Test.txt


Report •

#2
December 4, 2011 at 07:36:13
Thanks Loq; you solved my problem. You are the best.

Report •

#3
December 4, 2011 at 07:59:51
Hi again, I have a new problem please take a look at my source code and test it. I cant figure out whats wrong:
@echo off
title Binary Converter
color a
:begin
echo Welcome to the binary Translator
echo Please choose something to do.
echo.
echo (1) Encode
echo (2) Exit
echo.
set /p ans1=
IF %ans1%==1 goto encode
IF %ans1%==2 goto exit
cls
echo Your choise is invalid!
goto begin

:exit
cls
exit

:encode
cls
echo Please enter the Letters sepperatly, enter done when you are finished.
set /p let1=
goto encode1

:encode1
IF %let1%==A set /p var1= <01000001
IF %let1%==a set /p var2= <01000001
IF %let1%==B set /p var3= <01000010
IF %let1%==b set /p var4= <01000010
IF %let1%==C set /p var5= <01000011
IF %let1%==c set /p var6= <01000011
IF %let1%==D set /p var7= <01000100
IF %let1%==d set /p var8= <01000100
IF %let1%==E set /p var9= <01000101
IF %let1%==e set /p var10= <01000101
IF %let1%==F set /p var11= <01000110
IF %let1%==f set /p var12= <01000110
IF %let1%==G set /p var13= <01000111
IF %let1%==g set /p var14= <01000111
IF %let1%==H set /p var15= <01001000
IF %let1%==h set /p var16= <01001000
IF %let1%==I set /p var17= <01001001
IF %let1%==i set /p var18= <01001001
IF %let1%==J set /p var19= <01001010
IF %let1%==j set /p var20= <01001010
IF %let1%==K set /p var21= <01001011
IF %let1%==k set /p var22= <01001011
IF %let1%==L set /p var23= <01001100
IF %let1%==l set /p var24= <01001100
IF %let1%==M set /p var25= <01001101
IF %let1%==m set /p var26= <01001101
IF %let1%==N set /p var27= <01001110
IF %let1%==n set /p var28= <01001110
IF %let1%==O set /p var29= <01001111
IF %let1%==o set /p var30= <01001111
IF %let1%==P set /p var31= <01010000
IF %let1%==p set /p var32= <01010000
IF %let1%==Q set /p var33= <01010001
IF %let1%==q set /p var34= <01010001
IF %let1%==R set /p var35= <01010010
IF %let1%==r set /p var36= <01010010
IF %let1%==S set /p var37= <01010011
IF %let1%==s set /p var38= <01010011
IF %let1%==T set /p var39= <01010100
IF %let1%==t set /p var40= <01010100
IF %let1%==U set /p var41= <01010101
IF %let1%==u set /p var42= <01010101
IF %let1%==V set /p var43= <01010110
IF %let1%==v set /p var44= <01010110
IF %let1%==W set /p var45= <01010111
IF %let1%==w set /p var46= <01010111
IF %let1%==X set /p var47= <01011000
IF %let1%==x set /p var48= <01011000
IF %let1%==Y set /p var49= <01011001
IF %let1%==y set /p var50= <01011001
IF %let1%==Z set /p var51= <01011010
IF %let1%==z set /p var52= <01011010
IF %let1%==done goto exit2
IF %let1%==DONE goto exit2
goto encode


:exit2
set /p filename= <Bin_Output.txt
echo %filename%
pause
cls
exit


Report •

Related Solutions

#4
December 4, 2011 at 14:27:34
(Really sorry for the way it's laid out in long lines)
Just for your info
Just recently I made an encryption script which splits a sentence into each letter,
changes each letter to another then rebuilds it, and also converts it back to the
original sentence. Although the code is quite long for it. If you want the file to
tweak Add me on msn (Technetium@hotmail.co.uk) or I'll email it you. Just
let me know.

Ok So I've made yours work. Here's the entire new code. I hope this pastes properly.
Any questions/problems just ask :)

@echo off
SetLocal EnableDelayedExpansion
title Binary Converter
color a
SET no=0
:begin
echo Welcome to the binary Translator
echo Please choose something to do.
echo.
echo (1) Encode
echo (2) Exit
echo.
set /p ans1=
IF %ans1%==1 goto encode
IF %ans1%==2 goto EOF
cls
echo Your choice is invalid!
Pause
goto begin

:encode
cls
echo Please enter the Letters sepperatly, enter "done" when you are finished.
echo So far you have: !char1!!char2!!char3!!char4!!char5!!char6!!char7!!char8!!char9!!char10!!char11!!char12!!char13!!char14!!char15!!char16!!char17!!char18!!char19!!char20!!char21!!char22!!char23!!char24!!char25!!char26!!char27!!char28!!char29!!char30!!char31!!char32!!char33!!char34!!char35!!char36!!char37!!char38!!char39!!char40!!char41!!char42!!char43!!char44!!char45!!char46!!char47!!char48!!char49!!char50!!char51!!char52!!char53!!char54!!char55!!char56!!char57!!char58!!char59!!char60!!char61!!char62!!char63!!char64!!char65!!char66!!char67!!char68!!char69!!char70!!char71!!char72!!char73!!char74!!char75!!char76!!char77!!char78!!char79!!char80!!char81!!char82!!char83!!char84!!char85!!char86!!char87!!char88!!char89!!char90!!char91!!char92!!char93!!char94!!char95!!char96!!char97!!char98!!char99!!char100!
set /p "let1=>"
Set /a no=%no%+1

IF %let1%==A set var%no%= 01000001 & set char%no%=A
IF %let1%==a set var%no%= 01000001 & set char%no%=A
IF %let1%==B set var%no%= 01000010 & set char%no%=B
IF %let1%==b set var%no%= 01000010 & set char%no%=B
IF %let1%==C set var%no%= 01000011 & set char%no%=C
IF %let1%==c set var%no%= 01000011 & set char%no%=C
IF %let1%==D set var%no%= 01000100 & set char%no%=D
IF %let1%==d set var%no%= 01000100 & set char%no%=D
IF %let1%==E set var%no%= 01000101 & set char%no%=E
IF %let1%==e set var%no%= 01000101 & set char%no%=E
IF %let1%==F set var%no%= 01000110 & set char%no%=F
IF %let1%==f set var%no%= 01000110 & set char%no%=F
IF %let1%==G set var%no%= 01000111 & set char%no%=G
IF %let1%==g set var%no%= 01000111 & set char%no%=G
IF %let1%==H set var%no%= 01001000 & set char%no%=H
IF %let1%==h set var%no%= 01001000 & set char%no%=H
IF %let1%==I set var%no%= 01001001 & set char%no%=I
IF %let1%==i set var%no%= 01001001 & set char%no%=I
IF %let1%==J set var%no%= 01001010 & set char%no%=J
IF %let1%==j set var%no%= 01001010 & set char%no%=J
IF %let1%==K set var%no%= 01001011 & set char%no%=K
IF %let1%==k set var%no%= 01001011 & set char%no%=K
IF %let1%==L set var%no%= 01001100 & set char%no%=L
IF %let1%==l set var%no%= 01001100 & set char%no%=L
IF %let1%==M set var%no%= 01001101 & set char%no%=M
IF %let1%==m set var%no%= 01001101 & set char%no%=M
IF %let1%==N set var%no%= 01001110 & set char%no%=N
IF %let1%==n set var%no%= 01001110 & set char%no%=N
IF %let1%==O set var%no%= 01001111 & set char%no%=O
IF %let1%==o set var%no%= 01001111 & set char%no%=O
IF %let1%==P set var%no%= 01010000 & set char%no%=P
IF %let1%==p set var%no%= 01010000 & set char%no%=P
IF %let1%==Q set var%no%= 01010001 & set char%no%=Q
IF %let1%==q set var%no%= 01010001 & set char%no%=Q
IF %let1%==R set var%no%= 01010010 & set char%no%=R
IF %let1%==r set var%no%= 01010010 & set char%no%=R
IF %let1%==S set var%no%= 01010011 & set char%no%=S
IF %let1%==s set var%no%= 01010011 & set char%no%=S
IF %let1%==T set var%no%= 01010100 & set char%no%=T
IF %let1%==t set var%no%= 01010100 & set char%no%=T
IF %let1%==U set var%no%= 01010101 & set char%no%=U
IF %let1%==u set var%no%= 01010101 & set char%no%=U
IF %let1%==V set var%no%= 01010110 & set char%no%=V
IF %let1%==v set var%no%= 01010110 & set char%no%=V
IF %let1%==W set var%no%= 01010111 & set char%no%=W
IF %let1%==w set var%no%= 01010111 & set char%no%=W
IF %let1%==X set var%no%= 01011000 & set char%no%=X
IF %let1%==x set var%no%= 01011000 & set char%no%=X
IF %let1%==Y set var%no%= 01011001 & set char%no%=Y
IF %let1%==y set var%no%= 01011001 & set char%no%=Y
IF %let1%==Z set var%no%= 01011010 & set char%no%=Z
IF %let1%==z set var%no%= 01011010 & set char%no%=Z
IF %let1%==done goto exit2
IF %let1%==DONE goto exit2
goto encode


:exit2
Echo Enter your filename
set /p "filename=>"
echo !var1!!var2!!var3!!var4!!var5!!var6!!var7!!var8!!var9!!var10!!var11!!var12!!var13!!var14!!var15!!var16!!var17!!var18!!var19!!var20!!var21!!var22!!var23!!var24!!var25!!var26!!var27!!var28!!var29!!var30!!var31!!var32!!var33!!var34!!var35!!var36!!var37!!var38!!var39!!var40!!var41!!var42!!var43!!var44!!var45!!var46!!var47!!var48!!var49!!var50!!var51!!var52!!var53!!var54!!var55!!var56!!var57!!var58!!var59!!var60!!var61!!var62!!var63!!var64!!var65!!var66!!var67!!var68!!var69!!var70!!var71!!var72!!var73!!var74!!var75!!var76!!var77!!var78!!var79!!var80!!var81!!var82!!var83!!var84!!var85!!var86!!var87!!var88!!var89!!var90!!var91!!var92!!var93!!var94!!var95!!var96!!var97!!var98!!var99!!var100! >> %filename%.txt
Echo Completed.
pause


Report •

#5
December 4, 2011 at 21:18:55
THANKS THAT WORKS! IT GAVE ME THE REQUIRED .TXT FILE IN THE RIGHT WAY: ALL ON LINE ONE.
WOULD YOU PLEASE SEND ME THAT ENCODER SCRIPT OF YOURS: hercosmith03@gmail.com
Thanks you are by far the best batch programmer I have seen (not really see, you know what I mean)
Thanks Loq
Hitman

Report •

#6
December 20, 2011 at 08:33:58
really new to this so sorry if it's a dumb question, but what's the difference between this:

SET /p "userinput=>"

and this:

set /p userinput=

what does including quotation marks do?


Report •

#7
December 21, 2011 at 14:28:50
Hi Kim.

There's no difference, other than you get a nice > symbol when typing.
Instead of just a blank line

You could replace the > with something like
Type here:
Enter name:
Input:

Or something similar.


Report •

Ask Question