Batch file running differently

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Batch file running differently

#1 Post by Notelek_Labs » 22 Jul 2012 20:30

ok, lately my code has been acting weird. When run like normal, It works perfectly. When run by another batch file how ever, several errors occur.

Here's the code (Don't get overwhelmed)

Code: Select all

@echo off
color 47
IF EXIST F:/Security/Security.notl GOTO security
cd F:/DATA
title Notelek Assist
:test
:start
cls
echo           Welcome Back %username%!   
echo           8888888888888888888888888888888888888888888888888888888888
echo           8                        Beta 0.0.6                      8
echo           8  888b    888        888           888        888       8   
echo           8  8888b   888        888           888        888       8     
echo           8  88888b  888        888           888        888       8     
echo           8  888Y88b 888 .d88b. 888888 .d88b. 888 .d88b. 888  888  8
echo           8  888 Y88b888d88""88b888   d8P  Y8b888d8P  Y8b888 .88P  8
echo           8  888  Y88888888  888888   8888888888888888888888888K   8
echo           8  888   Y8888Y88..88PY88b. Y8b.    888Y8b.    888 "88b  8
echo           8  888    Y888 "Y88P"  "Y888 "Y8888 888 "Y8888 888  888  8
echo           8                                                        8
echo           8             d8888                d8b        888        8
echo           8            d88888                Y8P        888        8
echo           8           d88P888                           888        8
echo           8          d88P 888.d8888b .d8888b 888.d8888b 888888     8
echo           8         d88P  88888K     88K     88888K     888        8
echo           8        d88P   888"Y8888b."Y8888b.888"Y8888b.888        8
echo           8       d8888888888     X88     X88888     X88Y88b.      8
echo           8      d88P     888 88888P' 88888P'888 88888P' "Y888     8
echo           8                                                        8
echo           8                                                        8
echo           8              What would you like to do?                8
echo           8888888888888888888888888888888888888888888888888888888888
set /p m=
if "%m%"=="asdf" GOTO invalid
if "%m%"=="reboot" GOTO reboot
if "%m%"=="exit" exit
if "%m%"=="credits" GOTO credits
if "%m%"=="mute" GOTO mute
if "%m%"=="unmute" GOTO unmute
if "%m%"=="open cd drive" GOTO drive
if "%m%"=="term" GOTO term
if "%m%"=="screenshot" GOTO screenshot
if "%m%"=="color" GOTO color
if "%m%"=="teamview" GOTO team
if "%m%"=="help" GOTO help
if "%m%"=="edit" GOTO edit
if "%m%"=="calc" GOTO calc
if "%m%"=="search" GOTO search
if "%m%"=="mcs" GOTO ms
if "%m%"=="mcc" GOTO mc
if "%m%"=="cmd" GOTO 1
if "%m%"=="speak" GOTO speak
if "%m%"=="docs" GOTO docs

:invalid
cls
echo The command you entered is not in the system
pause
GOTO start

:speak
cls
echo What should I say?
set /p sp=
cls
echo Speaking...
nircmd.exe speak text %sp%
echo Done!
GOTO start

:1
cls
GOTO start2
:start5
cls
%com%
pause
:start2
echo           Welcome Back %username%!   
echo           8888888888888888888888888888888888888888888888888888888888
echo           8                        Beta 0.0.6                      8
echo           8  888b    888        888           888        888       8   
echo           8  8888b   888        888           888        888       8     
echo           8  88888b  888        888           888        888       8     
echo           8  888Y88b 888 .d88b. 888888 .d88b. 888 .d88b. 888  888  8
echo           8  888 Y88b888d88""88b888   d8P  Y8b888d8P  Y8b888 .88P  8
echo           8  888  Y88888888  888888   8888888888888888888888888K   8
echo           8  888   Y8888Y88..88PY88b. Y8b.    888Y8b.    888 "88b  8
echo           8  888    Y888 "Y88P"  "Y888 "Y8888 888 "Y8888 888  888  8
echo           8                                                        8
echo           8             d8888                d8b        888        8
echo           8            d88888                Y8P        888        8
echo           8           d88P888                           888        8
echo           8          d88P 888.d8888b .d8888b 888.d8888b 888888     8
echo           8         d88P  88888K     88K     88888K     888        8
echo           8        d88P   888"Y8888b."Y8888b.888"Y8888b.888        8
echo           8       d8888888888     X88     X88888     X88Y88b.      8
echo           8      d88P     888 88888P' 88888P'888 88888P' "Y888     8
echo           8                                                        8
echo           8              (To Get back type GOTO start)             8
echo           8                 Command Promt Portable                 8
echo           8888888888888888888888888888888888888888888888888888888888
set /p com=
GOTO start5

:ms
cls
ipconfig
echo The server is on Port 1
pause
echo Starting...
start Minecraft\Run.bat
ping localhost >nul
ping localhost >nul
GOTO mc

:mc
cls
start Run.bat
GOTO start

:edit
start notepad++.exe "Notelek_Assist.bat"
GOTO reboot

:help
cls
echo           Welcome Back %username%!   
echo           8888888888888888888888888888888888888888888888888888888888
echo           8                         Commands:                      8
echo           8                          reboot                        8
echo           8                           exit                         8
echo           8                          credits                       8
echo           8                           mute                         8
echo           8                          unmute                        8
echo           8                       open cd drive                    8
echo           8                           term                         8
echo           8                        screenshot                      8
echo           8                          color                         8
echo           8                         teamview                       8
echo           8                           help                         8
echo           8                           calc                         8
echo           8                          search                        8
echo           8                           cmd                          8
echo           8                                                        8
echo           8                Press any key to continue...            8
echo           8                                                        8
echo           8888888888888888888888888888888888888888888888888888888888
pause >nul
GOTO start


:calc
cls
echo Enter your Operator
set/p op=
cls
echo Enter your First Number
set/p num1=
cls
echo Enter your Second Number
set/p num2=
cls
if "%op%"=="asdf" GOTO invalidc
if "%op%"=="exit" GOTO start
if "%op%"=="+" GOTO calc+
if "%op%"=="-" GOTO calc-
if "%op%"=="*" GOTO calc*
if "%op%"=="/" GOTO calc/

:invalidc
cls
echo Type in a valid operator
pause
GOTO reboot

:calc+
cls
set /a answer=num1+num2
echo %num1%+%num2%=%answer%
pause
GOTO start

:calc-
cls
set /a answer=num1-num2
echo %num1%-%num2%=%answer%
pause
GOTO start

:calc*
cls
set /a answer=num1*num2
echo %num1%*%num2%=%answer%
pause
GOTO start

:calc/
cls
set /a answer=num1/num2
echo %num1%/%num2%=%answer%
pause
GOTO start


:security
cls
echo           Welcome Back %username%!   
echo           88888888888888888888888888888888888888888888888888888888888
echo           8 WARNING: Attempted Acess! Acess Logs in Security folder 8
echo           88888888888888888888888888888888888888888888888888888888888
pause
goto test

:team
cls
echo         888888888888888888888888888888888888888888888888888888888888
echo         8 The Notelek Server 1 Teamviewer id is in your clipboard. 8
echo         888888888888888888888888888888888888888888888888888888888888
nircmd.exe clipboard set Cencored
ping localhots >nul
GOTO start

:eclipse
start eclipse/eclipse.exe
GOTO start

:reboot
start reboot.bat
exit

:credits
cls
echo Notelek assist was coded mostly by Matthew Foulks, Ceo of Notelek Inc.
echo Notelek assist makes use of nircmd, released as freeware by Nirsoft inc.
pause
GOTO start

:mute
nircmd.exe mutesysvolume 1
GOTO start

:unmute
nircmd.exe mutesysvolume 0
GOTO start

:drive
nircmd.exe cdrom open J:
nircmd.exe cdrom open Y:
nircmd.exe cdrom open D:
GOTO start

:term
cls
echo Which process should I terminate?
tasklist
set /p term=
nircmd.exe killprocess %term%
GOTO start

:screenshot
del ../Shot.png
nircmd.exe savescreenshot "../Shot.png"
GOTO start

:invalidcolor
cls
echo Please Enter a valid combo.
pause
GOTO color

:color
cls
echo you can choose your color sceme here (type in the line that you want)
echo white on red
echo gray on black
echo black on white
echo pink on purple
echo aqua on black
echo blue on red
set /p color=
if "%color%"=="asdkf" GOTO invalidcolor
if "%color%"=="white on red" GOTO c1
if "%color%"=="gray on black" GOTO c2
if "%color%"=="black on white" GOTO c3
if "%color%"=="pink on purple" GOTO c4
if "%color%"=="aqua on black" GOTO c5
if "%color%"=="blue on red" GOTO c6

:c1
color 47
echo 47 >file.save
GOTO start
:c2
color 08
echo 08 >file.save
GOTO start
:c3
color 0F
echo 0F >file.save
GOTO start
:c4
color D5
echo D5 >file.save
GOTO start
:c5
color 30
echo 30 >file.save
GOTO start
:c6
color 14
echo 14 >file.save
GOTO start

:search
cls
echo           Welcome Back %username%!   
echo           8888888888888888888888888888888888888888888888888888888888
echo           8                        Beta 0.0.6                      8
echo           8  888b    888        888           888        888       8   
echo           8  8888b   888        888           888        888       8     
echo           8  88888b  888        888           888        888       8     
echo           8  888Y88b 888 .d88b. 888888 .d88b. 888 .d88b. 888  888  8
echo           8  888 Y88b888d88""88b888   d8P  Y8b888d8P  Y8b888 .88P  8
echo           8  888  Y88888888  888888   8888888888888888888888888K   8
echo           8  888   Y8888Y88..88PY88b. Y8b.    888Y8b.    888 "88b  8
echo           8  888    Y888 "Y88P"  "Y888 "Y8888 888 "Y8888 888  888  8
echo           8                                                        8
echo           8             d8888                d8b        888        8
echo           8            d88888                Y8P        888        8
echo           8           d88P888                           888        8
echo           8          d88P 888.d8888b .d8888b 888.d8888b 888888     8
echo           8         d88P  88888K     88K     88888K     888        8
echo           8        d88P   888"Y8888b."Y8888b.888"Y8888b.888        8
echo           8       d8888888888     X88     X88888     X88Y88b.      8
echo           8      d88P     888 88888P' 88888P'888 88888P' "Y888     8
echo           8                                                        8
echo           8                                                        8
echo           8             Please Enter Your Search Terms             8
echo           8888888888888888888888888888888888888888888888888888888888
set /p SC=
cls
echo           Welcome Back %username%!   
echo           8888888888888888888888888888888888888888888888888888888888
echo           8                        Beta 0.0.6                      8
echo           8  888b    888        888           888        888       8   
echo           8  8888b   888        888           888        888       8     
echo           8  88888b  888        888           888        888       8     
echo           8  888Y88b 888 .d88b. 888888 .d88b. 888 .d88b. 888  888  8
echo           8  888 Y88b888d88""88b888   d8P  Y8b888d8P  Y8b888 .88P  8
echo           8  888  Y88888888  888888   8888888888888888888888888K   8
echo           8  888   Y8888Y88..88PY88b. Y8b.    888Y8b.    888 "88b  8
echo           8  888    Y888 "Y88P"  "Y888 "Y8888 888 "Y8888 888  888  8
echo           8                                                        8
echo           8             d8888                d8b        888        8
echo           8            d88888                Y8P        888        8
echo           8           d88P888                           888        8
echo           8          d88P 888.d8888b .d8888b 888.d8888b 888888     8
echo           8         d88P  88888K     88K     88888K     888        8
echo           8        d88P   888"Y8888b."Y8888b.888"Y8888b.888        8
echo           8       d8888888888     X88     X88888     X88Y88b.      8
echo           8      d88P     888 88888P' 88888P'888 88888P' "Y888     8
echo           8                                                        8
echo           8                                                        8
echo           8                       Working...                       8
echo           8888888888888888888888888888888888888888888888888888888888
start "" /b "PortableApps\GoogleChromePortable\GoogleChromePortable.exe" "http://www.google.com/search?q=%SC%"
ping localhost >nul
GOTO test

:docs
cls
echo           Welcome Back %username%!   
echo           8888888888888888888888888888888888888888888888888888888888
echo           8                        Beta 0.0.6                      8
echo           8  888b    888        888           888        888       8   
echo           8  8888b   888        888           888        888       8     
echo           8  88888b  888        888           888        888       8     
echo           8  888Y88b 888 .d88b. 888888 .d88b. 888 .d88b. 888  888  8
echo           8  888 Y88b888d88""88b888   d8P  Y8b888d8P  Y8b888 .88P  8
echo           8  888  Y88888888  888888   8888888888888888888888888K   8
echo           8  888   Y8888Y88..88PY88b. Y8b.    888Y8b.    888 "88b  8
echo           8  888    Y888 "Y88P"  "Y888 "Y8888 888 "Y8888 888  888  8
echo           8                                                        8
echo           8             d8888                d8b        888        8
echo           8            d88888                Y8P        888        8
echo           8           d88P888                           888        8
echo           8          d88P 888.d8888b .d8888b 888.d8888b 888888     8
echo           8         d88P  88888K     88K     88888K     888        8
echo           8        d88P   888"Y8888b."Y8888b.888"Y8888b.888        8
echo           8       d8888888888     X88     X88888     X88Y88b.      8
echo           8      d88P     888 88888P' 88888P'888 88888P' "Y888     8
echo           8                                                        8
echo           8                                                        8
echo           8                       Working...                       8
echo           8888888888888888888888888888888888888888888888888888888888
start "" /b "PortableApps\GoogleChromePortable\GoogleChromePortable.exe" "http://174.108.108.195:8080/login/"
cls
GOTO start

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Batch file running differently

#2 Post by Liviu » 22 Jul 2012 21:38

Notelek_Labs wrote:When run by another batch file how ever, several errors occur.

You have an error on line 42 of the other batch file ;-)

Since you give no meaningful details on the context or the actual errors, only wild guess would be to try and replace "cd F:/DATA" by "pushd F:\DATA" (and pair it with a "popd" for good measure).

Liviu

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file running differently

#3 Post by foxidrive » 22 Jul 2012 21:46

Something I see is that before every set /p input line, you should nul the variable.

If it is not nulled and the user presses enter then the variable will not be nulled or changed, and will be set to what it was before the routine was entered.

Try this - it can lead to unintended behaviour.

Code: Select all

@echo off
set variable=oops
set /p "variable=Just press enter: "
echo.%variable%


As opposed to this:

Code: Select all

@echo off
set "variable="
set /p "variable=Just press enter: "
echo.%variable%

Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Re: Batch file running differently

#4 Post by Notelek_Labs » 23 Jul 2012 07:12

Just to clarify, the errors I get are that when I runn the program with another program, it appears to work but then i type in a command like help, and it goes straight to the command promt help, not mine. (aka the if statments dont work)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file running differently

#5 Post by foxidrive » 23 Jul 2012 07:42

Notelek_Labs wrote:Just to clarify, the errors I get are that when I runn the program with another program, it appears to work but then i type in a command like help, and it goes straight to the command promt help, not mine. (aka the if statments dont work)



I ran it and typed help and your help screen is what was shown.

What do you mean "when I runn the program with another program"

Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Re: Batch file running differently

#6 Post by Notelek_Labs » 23 Jul 2012 08:13

by that I mean another batch file had this
(notelek_assist is the name of the program (just so you know, it uses nircmd))
start "" /b "Notelek_assist.bat"

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Batch file running differently

#7 Post by abc0502 » 23 Jul 2012 08:43

i think batch files should be called using the Call command it's safer

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file running differently

#8 Post by foxidrive » 23 Jul 2012 08:57

Notelek_Labs wrote:by that I mean another batch file had this
(notelek_assist is the name of the program (just so you know, it uses nircmd))
start "" /b "Notelek_assist.bat"


Which batch file do you have problems with? Maybe it's the other one.

Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Re: Batch file running differently

#9 Post by Notelek_Labs » 23 Jul 2012 09:54

I just fixed most of the problems by just combining the two batch files into 1, making it an exe (so people can't see or edit the code) and running that.

Post Reply