Hack Forums
[Shell] Super, super basic batch help..? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Super, super basic batch help..? (/showthread.php?tid=2900213)



Super, super basic batch help..? - Cathal - Sep 28, 2012

Can someone explain what I am doing wrong here..?

As soon as I run the program it opens and closes immediately :/

It worked fine until I added the "if exist" shit, so presumably the syntax in there is fucked. I've never really used the "if" statement, so please take it easy on me :)

Code
@echo off

:CreateDataBase
    if exist "C:\Documents and Settings\Admin\database.txt"
    (
        goto Start
    )
    echo DATABASE SUCCESSFULLY CREATED >database.txt

:Start
    set /p account=Do you have an account?
        if %account%==yes goto Login
        if %account%==no goto Create

:Create
    cls
    set /p newusername=Please enter your new username:
    findstr /m "%newusername%" database.txt
    if %errorlevel%==0
    (
        goto NameInUse
    )
    goto NewPass
    
:NameInUse
    echo Error... Username is already taken! Please try again.
    pause>nul
    goto Create

:NewPass
    set /p newpass=Please choose a password:
    echo %newusername%--%newpass% >>database.txt
    echo Account Created! Please Login.
    pause>nul
    goto Login



* - DesuDesuDesuDesu - Sep 28, 2012

I would make the first parenthesis AFTER the " with a space between it.
Code
@echo off
:CreateDataBase
if exist "C:\Documents and Settings\Admin\database.txt" (
goto Start
    )
echo DATABASE SUCCESSFULLY CREATED >database.txt
:Start
set /p account=Do you have an account?



* - Cathal - Sep 28, 2012

(Sep 28, 2012 03:28 PM)Fenguepay Wrote:  I would make the first parenthesis AFTER the " with a space between it.
Code
@echo off
:CreateDataBase
if exist "C:\Documents and Settings\Admin\database.txt" (
goto Start
    )
echo DATABASE SUCCESSFULLY CREATED >database.txt
:Start
set /p account=Do you have an account?

Why thank you! It worked, im used to JAVA formatting I guess.. Can someone else +rep him for being helpful? :B I would, but well you know..