1.

Solve : What did I do wrong??

Answer»

I have a bunch of joke programs on my computer (NAV doesn't like it, the old codger) and some are customizable with the command prompt. I'm writing a batch file to execute these programs with these special functions.

Each time I INPUT something into the prompt (namely, a PROGRAM file) the program swears up and down the program doesn't exist. Why? What did I mess up at?

Code: [Select]@ECHO OFF
cls
ECHO This batch file will simulate a bombed program. It will place it in the startup
ECHO folder so it will run at next startup.
:begin
set choice=
set /p choice=Choose program to bomb:

IF EXIST %choice% GOTO create

ECHO Sorry, the specified program does not exist.
GOTO begin
This is only a block; ":create" does exist in the file.The batch file looks reasonable. What exactly did you type at the prompt? Drive and pathname would required unless the bomb program exists in the current directory along with the batch file. The IF EXIST will not search the PATH as would a procedure call.

Just my 2¢ worth. 8-)I knew I was in C:\Utilities, so I typed in

C:\Program FILES\Opera\Opera.exe

A quick check of my quick-launch shortcut shows the file does exist at that directory.With an embedded space in the path, you would need to quote your entry:

"C:\Program Files\Opera\Opera.exe"

8-)Thank you.

I have one other issue. I want to create batch files with another batch file. I followed the code posted here but it didn't work.

My full code:

Code: [Select]@ECHO OFF
cls
ECHO This batch file will simulate a bombed program. It will place it in the startup
ECHO folder so it will run at next startup.
:begin
set choice=
set /p choice=Choose program to bomb:

IF EXIST %choice% GOTO create

ECHO Sorry, the specified program does not exist.
GOTO begin

:create
REM - creates the batch file and writes it
ECHO @echo off > bombtemp.bat
ECHO cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\ > bombtemp.bat
ECHO @echo off > bombtemp2.bat
ECHO cd \Documents and Settings\Timothy\Desktop\Desktop Games\ > bombtemp2.bat
ECHO bomb.exe '%choice%' > bombtemp2.bat
ECHO cd \utilities > bombtemp2.bat
call bombtemp.bat
del bombtemp.batYou would need to use >> for all but the first line to be outputted. This will ensure you get a new COPY of your batch file each time it runs and that the lines are appended to the file and not overwritten.

I belive the link you provided made that point. Quote

create
REM - creates the batch file and writes it
ECHO @echo off >> bombtemp.bat
ECHO cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\ > bombtemp.bat
ECHO @echo off > bombtemp2.bat
ECHO cd \Documents and Settings\Timothy\Desktop\Desktop Games\ > bombtemp2.bat
ECHO bomb.exe '%choice%' >> bombtemp2.bat
ECHO cd \utilities >> bombtemp2.bat
call bombtemp.bat
del bombtemp.bat

You may have missed a few, also create needs a colon in front. I presume that bombtemp and bombtemp2 are meant to be two different files.

Code: [Select]:create
REM - creates the batch file and writes it
ECHO @echo off > bombtemp.bat
ECHO cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\ >> bombtemp.bat
ECHO @echo off > bombtemp2.bat
ECHO cd \Documents and Settings\Timothy\Desktop\Desktop Games\ >> bombtemp2.bat
ECHO bomb.exe '%choice%' >> bombtemp2.bat
ECHO cd \utilities >> bombtemp2.bat
call bombtemp.bat
del bombtemp.bat

8-)OK, I revised that code. My intention is as follows:

Write a "bombtemp.bat" batch file, which includes instructions to create another batch file in the startup folder, which will execute the code.

Ideally, I should have the following in the end:

In C:\Utilities\bombtemp.bat:

Code: [Select]cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\
@echo off > bombtemp2.bat
cd \Documents and Settings\Timothy\Desktop\Desktop Games\ >> bombtemp2.bat
bomb.exe '%choice%' >> bombtemp2.bat
cd \utilities >> bombtemp2.bat
In C:\Documents and Settings\Timothy\Start Menu\Programs\Startup\bombtemp2.bat:

Code: [Select]@echo off
cd \Documents and Settings\Timothy\Desktop\Desktop Games\
bomb.exe '%choice%'
cd \utilities
And that's it. I used this batch file to achieve this:

Code: [Select]@ECHO OFF
cls
ECHO This batch file will simulate a bombed program. It will place it in the startup
ECHO folder so it will run at next startup.
:begin
set choice=
set /p choice=Choose program to bomb:

IF EXIST %choice% GOTO create

ECHO Sorry, the specified program does not exist.
GOTO begin

:create
REM - creates the batch file and writes it
ECHO @echo off > bombtemp.bat
ECHO cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\ >> bombtemp.bat
ECHO @echo off > bombtemp2.bat >> bombtemp.bat
ECHO cd \Documents and Settings\Timothy\Desktop\Desktop Games\ >> bombtemp2.bat >> bombtemp.bat
ECHO bomb.exe '%choice%' >> bombtemp2.bat >> bombtemp.bat
ECHO cd \utilities >> bombtemp2.bat >> bombtemp.bat
call bombtemp.bat
What I got was "bombtemp.bat" in the startup folder with this code:

Code: [Select]@echo off
cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\
@echo off
cd \Documents and Settings\Timothy\Desktop\Desktop Games\
bomb.exe '"C:\Program Files\Opera\Opera.exe"'
cd \utilities
What the heck did I do wrong?Somewhere along the way this seems to have changed. In any case you need to escape certain characters to pass them thru a redirection:

^> should pass a single > to the output file
^>^> should pass a double >> to the output file

You just gotta love the brains that came up with this stuff.


Discussion

No Comment Found