|
Answer» I'm writing a messenger for me and my brother to use at our house. I'm Just having a little trouble with it.
Here's what I have so far,
Code: [Select]ECHO OFF
IF EXIST Writer.bat ( IF EXIST READER.bat (GOTO DONE ) ELSE ( GOTO Reader ) ) ELSE ( GOTO Writer )
:Reader
ECHO ECHO OFF>Reader.bat ECHO.>>Reader.bat ECHO :Loop>>Reader.bat ECHO.>>Reader.bat ECHO CLS>>Reader.bat ECHO TYPE Messages.txt>>Reader.bat >>Reader.bat ECHO TIMEOUT /t 2 ECHO GOTO Loop>>Reader.bat
ATTRIB +H Reader.bat
ECHO Reader Successfully Created.
IF EXIST Writer.bat (GOTO Done ) ELSE ( GOTO Writer )
:Writer
ECHO ECHO OFF>Writer.bat ECHO.>>Writer.bat ECHO ECHO Enter your name:>>Writer.bat ECHO SET /p User="">>Writer.bat ECHO.>>Writer.bat ECHO :Loop>>Writer.bat ECHO.>>Writer.bat ECHO CLS>>Writer.bat ECHO ECHO Enter your message:>>Writer.bat ECHO SET /p Message="">>Writer.bat >>Messages.txt ECHO ECHO %%User%% - %%Message%%>>Writer.bat >>Messages.txt ECHO ECHO.>>Writer.bat ECHO GOTO Loop>>Writer.bat
ATTRIB +H Writer.bat
ECHO Writer Successfully Created.
IF EXIST Reader.bat (GOTO Done ) ELSE ( GOTO Reader )
:Done
PAUSE START Reader.bat START Writer.bat EXIT The parts I'm having troubles with is:
Code: [Select]>>Writer.bat ECHo ECHO %%User%% - %%Message%%>>Messages.txt >>Writer.bat ECHO.>>Messages.txt And:
Code: [Select]>>Reader.bat ECHO TIMEOUT /t 2 The first one I really wasn't expecting to work, does anybody know a way around it?
And the second, I really don't know why it's not working. Any Ideas?>>Reader.bat ECHO TIMEOUT /t 2 No problems with this line, it appears it will be written to Reader.bat but does Timeout have a /t switch?
Code: [Select]>>Writer.bat ECHO ECHO %%User%% - %%Message%%>>Messages.txt >>Writer.bat ECHO.>>Messages.txt Escape the second >> using the caret like
Code: [Select]>>Writer.bat ECHO ECHO %%User%% - %%Message%%^>^>Messages.txt >>Writer.bat ECHO ECHO.^>^>Messages.txt This doesn't mean your script will run, I think there are other problems for you to sort out..
FYI to save a lot of repetitive typing you could use
( ECHO ECHO OFF ECHO ECHO. ECHO SET /p User=Enter your name: ECHO ECHO. etc... . . etc... )>writer.bat
Good luck.Ahh, thank you very much!
I am aware of the bugs, and am still working on them. These two were the ones stumping me.
And by the way:
Code: [Select]C:\>timeout /?
TIMEOUT [/T] timeout [/NOBREAK]
Description: This utility accepts a timeout parameter to wait for the specified time period (in seconds) or until any key is pressed. It also accepts a parameter to ignore the key press.
Parameter List: /T timeout Specifies the number of seconds to wait. Valid range is -1 to 99999 seconds.
/NOBREAK Ignore key presses and wait specified time.
/? Displays this help message.
NOTE: A timeout value of -1 means to wait indefinitely for a key press.
Examples: TIMEOUT /? TIMEOUT /T 10 TIMEOUT /T 300 /NOBREAK TIMEOUT /T -1
C:\> Thanks for the suggestions!Timeout /t SORRY about that, it's your Win 7 vs my Win XP. LOL Haha yeah, not a problem! Thanks again.
Quote from: Dusty on AUGUST 17, 2010, 09:28:32 PM FYI to save a lot of repetitive typing you could use
( ECHO ECHO OFF ECHO ECHO. ECHO SET /p User=Enter your name: ECHO ECHO. etc... . . etc... )>writer.bat
Good luck.
WOW! You can actually do that? Dang...that could have saved tonnes of time!
Quote from: helpmehWOW! You can actually do that?
Yep, try it out.
|