Jump to content


 

Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Hello World! is boring, anyone know how to expand on it?


  • Please log in to reply
9 replies to this topic

#1 Purplegill10

Purplegill10

    Member

  • Members
  • PipPip
  • 90 posts
  • Gender:Male
  • Location:Somewhere in the 4th wall

Posted 18 August 2012 - 12:43 AM

So basically I found out what a batch file really was and found that .bat files could be used for the Hello World! program.
I was wondering, how can I take that and then assign different keys to say different things?

From a curious--Gilroy

EDIT: Not exactly sure this is in the right forum :/

Edited by Blade, 18 August 2012 - 12:45 PM.
Moved to Programming

Even if you are a minority of one, the truth is the truth.
If I had no sense of humor, I would long ago have committed suicide.
Justice that love gives is a surrender, justice that law gives is a punishment.
-Mahatma Gandhi

Gandhi was freakin' awesome

 

  • BC Ads
  • BleepingComputer.com

#2 jake gardner

jake gardner

    Member

  • Members
  • PipPip
  • 22 posts

Posted 11 September 2012 - 08:27 PM

Where it says "hello world" change it
eg.
echo hello world
@echo off
sleep 5
echo goodbye world
@echo off
sleep 5



that will display hello world then wait and then say good by world

#3 Purplegill10

Purplegill10

    Member

  • Members
  • PipPip
  • 90 posts
  • Gender:Male
  • Location:Somewhere in the 4th wall

Posted 11 September 2012 - 08:34 PM

Awesome, thx for the reply
Even if you are a minority of one, the truth is the truth.
If I had no sense of humor, I would long ago have committed suicide.
Justice that love gives is a surrender, justice that law gives is a punishment.
-Mahatma Gandhi

Gandhi was freakin' awesome

#4 myrti

myrti

    Animin made me do it...

  • Malware Response Instructor
  • PipPipPipPipPipPip
  • 29,580 posts
  • Gender:Female
  • Location:At home

Posted 12 September 2012 - 09:42 AM

Hi,

you can alter the size of your window with the command mode con cols=number lines=number, where number needs to be replaced with a number to define the size. You can use the command color to change the color of your command line. COLOR c0 will create black writings on a red background. The command title, will alter the title-bar of your batch.

title my first batch
echo hello world
@echo off
sleep 5
color c0
echo goodbye world
@echo off
sleep 5

this batch will change the title to say "my first batch" and change the color between saying hello world and goodbye world.

regards myrti

I will be gone from the 17th to the 27th of May


If I have been helping you and haven't replied in 2 days, feel free to shoot me a PM!
If I have helped you and you would like to donate, please click here
Please don't send help request via PM, unless I am already helping you. Use the forums!


signew2_zps0a005319.jpg


#5 Purplegill10

Purplegill10

    Member

  • Members
  • PipPip
  • 90 posts
  • Gender:Male
  • Location:Somewhere in the 4th wall

Posted 12 September 2012 - 09:13 PM

thanks again, never knew you could do that :lol:
Even if you are a minority of one, the truth is the truth.
If I had no sense of humor, I would long ago have committed suicide.
Justice that love gives is a surrender, justice that law gives is a punishment.
-Mahatma Gandhi

Gandhi was freakin' awesome

#6 DarkSnake-Kobra

DarkSnake-Kobra

    Senior Member

  • Malware Study Hall Junior
  • PipPipPipPip
  • 582 posts
  • Gender:Male
  • Location:Iowa, USA

Posted 12 September 2012 - 10:08 PM

I didn't know ether that you could do colors. B)

#7 luke127

luke127

    Member

  • Members
  • PipPip
  • 39 posts
  • Gender:Male
  • Location:NSW Australia

Posted 13 September 2012 - 01:18 AM

Generally @ echo off is at the top of page. So it affects ALL commands under it. It won't ruin your code because I wrote a similar script myself :)

#8 AceInfinity

AceInfinity

    Member

  • Members
  • PipPip
  • 15 posts
  • Gender:Male
  • Location:Canada

Posted 23 September 2012 - 11:42 PM

Where it says "hello world" change it
eg.
echo hello world
@echo off
sleep 5
echo goodbye world
@echo off
sleep 5



that will display hello world then wait and then say good by world



Hi,

you can alter the size of your window with the command mode con cols=number lines=number, where number needs to be replaced with a number to define the size. You can use the command color to change the color of your command line. COLOR c0 will create black writings on a red background. The command title, will alter the title-bar of your batch.

title my first batch
echo hello world
@echo off
sleep 5
color c0
echo goodbye world
@echo off
sleep 5

this batch will change the title to say "my first batch" and change the color between saying hello world and goodbye world.

regards myrti


@Above - I don't understand though, why you're using @echo off more than once within the same script when it was always off even at the point in time of calling it a second time?? You only need it once, and as this guy stated:

Generally @ echo off is at the top of page. So it affects ALL commands under it. It won't ruin your code because I wrote a similar script myself :)


That is correct, it's typically at the top of your code, and you don't have to set it again. You should also be using PING instead of SLEEP because it consumes less processor time.

@OP - Fool around with some loops, and variable modifiers. Start out with making a basic addition calculator with user input for the first and second numbers, output the total. Be sure to use the /a switch for mathematical operations with variables involved.

Edited by AceInfinity, 23 September 2012 - 11:46 PM.


#9 KingDavidlll

KingDavidlll

    New Member

  • Members
  • Pip
  • 3 posts

Posted 25 September 2012 - 05:02 PM

I haven't really done much with batch, but you can assign different keys (although you will have to press enter after) to do different things by using a variable and if statements.

Example:
@echo off
:top
set /p var=Type 'a', 'b' or 'c': 
if "%var%"=="a" (
    echo Hello World
)
if "%var%"=="b" (
    echo Too good for Hello World?
)
if "%var%"=="c" (
    echo Oh well Good Bye!
    goto :end
)
pause
goto :top
:end


#10 AceInfinity

AceInfinity

    Member

  • Members
  • PipPip
  • 15 posts
  • Gender:Male
  • Location:Canada

Posted 25 September 2012 - 11:25 PM

Actually, in XP or later I believe, there's the CHOICE command (executable in an environment location as choice.exe) that you can use. It allows you to input without having to press ENTER.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users