Page 1 of 1

Log User Input

Posted: 18 May 2011 17:23
by alleypuppy
Hello, fellow Batch writers!

I'm working on a messenger batch file and I would like to log up to 10 recent recipients. However, I have never written a Batch file that logs data, so I'm not sure how to do it.

I searched Google for an answer, but I couldn't find what I'm looking for.

Here's the file:


    @echo off
    title Messenger
    sc config messenger start= demand
    sc start messenger
    cls
    echo Welcome to Messenger!
    echo.
    set /p command=Computer Name or Internal IP Address:
    echo.
    set /p message=Message:
    net send %command% %message%
    echo.
    echo Press "Enter" to send another message to the same computer, type "r" to view
    echo recent recipients, or enter the Computer Name or Internal IP Address of another
    echo computer to send a message to a different computer.
    echo.
    set /p command=^>
    if /I "%command%"=="r" goto C
    if /I "%command%"=="" goto A
    goto B

    :A
    Cls
    echo Recipient: %command%
    set /p message=Message:
    net send %command% %message%
    echo.
    echo Press "Enter" to send another message to the same computer, type "r" to view
    echo recent recipients, or enter the Computer Name or Internal IP Address of another
    echo computer to send a message to a different computer.
    echo.
    set /p command=^>
    if /I "%command%"=="r" goto C
    if /I "%command%"=="" goto A
    goto B

    :B
    cls
    echo Recipient: %command%
    echo.
    set /p message=Message:
    net send %command% %message%
    echo.
    echo Press "Enter" to send another message to the same computer, type "r" to view
    echo recent recipients, or enter the Computer Name or Internal IP Address of another
    echo computer to send a message to a different computer.
    echo.
    set /p command=^>
    if /I "%command%"=="r" goto C
    if /I "%command%"=="" goto A
    goto B

    :C
    cls
    type UserLog.log
    echo.
    echo.
    set /p command=Computer Name or Internal IP Address:
    goto B


If you want to test it, type in your internal IP address (the one your router gives you) or your computer name as the recipient.

Thanks for any help! :wink:

Re: Log User Input

Posted: 18 May 2011 18:52
by Ed Dyreen

Code: Select all

@echo off &SetLocal EnableExtensions EnableDelayedExpansion

>out.tmp (
     echo."heloo world !"
)
set /p ?=< "out.tmp"
echo.?=%?%_

set /p "?=input and press enter : " <nul
set /p "?=input and press enter : " >nul
echo.?=%?%_

pause
exit

Re: Log User Input

Posted: 18 May 2011 19:59
by alleypuppy
Ed Dyreen wrote:

Code: Select all

@echo off &SetLocal EnableExtensions EnableDelayedExpansion

>out.tmp (
     echo."heloo world !"
)
set /p ?=< "out.tmp"
echo.?=%?%_

set /p "?=input and press enter : " <nul
set /p "?=input and press enter : " >nul
echo.?=%?%_

pause
exit


This isn't exactly what I'm looking for. I need the text that I type to be sent to the log file.

Also, is there any way to overwrite logs in the same file after 10 have been saved?