Solved Returns : ECHO is off in .txt file..

November 3, 2015 at 12:58:14
Specs: Windows 7
Everytime regardless if i enter a proper path or email it returns with a "ECHO is off" in the .txt file.
Does anyone know what I'm doing wrong?

:start
cls
set /p EOD= Do you want to back up to an email(1) a destination on your computer(2) or both(3) (1, 2, 3)?

if %EOD% == 1 (
set /p EMAIL= Enter the email you want to send too:
echo %EMAIL% > email.txt
) else if %EOD% == 2 (
set /p DESTINATION= Enter the path of the destination you want to back up to:
echo %DESTINATION% > destination.txt
) else if %EOD% == 3 (
set /p EMAIL= Enter the email you want to send too:
echo %EMAIL% > email.txt
set /p DESTINATION= Enter the path of the destination you want to back up to:
echo %DESTINATION% > destination.txt
)

message edited by SparkScripts


See More: Returns : ECHO is off in .txt file..

Report •

#1
November 3, 2015 at 13:58:02
Looks like either %EMAIL% or %DESTINATION% is undefined.

Here are some suggestions and a modified script with the changes implemented.

1: Use delayed variable expansion, it's a good routine to enable it in the beginning of each script. (Delayed expansion variables uses ! instead of %)
2: Remove the else and else if clauses, you don't need those.
3: Enclose the "question text" on the set /p commands with quotes.
4: Just for safety, you can set EOD to be 0 before asking for the value

@echo off
setlocal enabledelayedexpansion
:start
cls
set EOD=0
set /p EOD="Do you want to back up to an email[1] A destination on your computer [2] or both [3]? "
if !EOD!==0 (
goto :start
)
if !EOD!==1 (
echo !EMAIL! > email.txt
)
if !EOD!==2 (
set /p DESTINATION="Enter the path of the destination you want to back up to: "
echo !DESTINATION! > destination.txt
)
if !EOD!==3 (
set /p EMAIL="Enter the email you want to send too: "
echo !EMAIL! > email.txt
set /p DESTINATION="Enter the path of the destination you want to back up to: "
echo !DESTINATION! > destination.txt
)
pause > nul

Let me know if it works out

Marking answers that solve, or help helps you solve a problem as "Best Answer" also helps other people solve similiar ones in the future.

message edited by RainBawZ


Report •

#2
November 3, 2015 at 17:02:44
✔ Best Answer
Yeh, Your "IF" structure is totally off the rails. In situations like this, I usually use this approach:

@echo off & setlocal enabledelayedexpansion
:start
set eod=
set /p eod=Do you want to back up to an email(1) a destination on your computer(2) or both(3) (1, 2, 3)?
call :%eod%||goto :abort
goto :eof

:1
set EMAIL=
echo -------------------------
set /p EMAIL= Enter the email you want to send to:
if not defined EMAIL goto :abort
echo %EMAIL% > email.txt
echo email backup is set to:
type email.txt
goto :eof

:2
set DESTINATION=
echo -------------------------
set /p DESTINATION= Enter the path of the destination you want to back up to:
if not defined DESTINATION goto :abort
echo %DESTINATION% > destination.txt
echo local drive destination is set to:
type destination.txt
goto :eof

:3
call :1
call :2
goto :eof

:abort
echo insufficient or invalid specs were entered. aborting backup.

::----------- end batch, not tested

message edited by nbrane


Report •

#3
November 4, 2015 at 07:07:42
Thanks nbran that helped insanely.

Ive never created a batchfile before. And your assistance is much appreiciated.


Report •

Related Solutions

#4
November 4, 2015 at 07:08:15
Thanks nbran. That worked :D

Report •

Ask Question