1

Though I can find few relevant questions such as Displaying Windows command prompt output and redirecting it to a file and How do I echo and send console output to a file in a bat script?, I could not fix my problem. I am working on Windows XP and running a few scripts using a batch file which uses STDIN and STDOUT handles.

Basically, I want to save the log file of command prompt. This is possible with "echo >> log.txt" in a batch file. However, this is not saving the outputs generated as a result of the script file. So I tried at the cmd prompt itself as D:>file.bat >"dir_path/log.txt". Again, this command saves the STDOUT to log.txt at the specified location. Since I need to get a few user inputs i.e. to use the STDIN handle, how do I achieve this in addition to saving the outputs of command prompts in separate file too?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sumathi Gokul
  • 101
  • 2
  • 8
  • I've used this [article](https://blogs.msdn.microsoft.com/toub/2006/05/03/low-level-mouse-hook-in-c/) to create [this](https://github.com/npocmaka/batch.scripts/blob/master/hybrids/.net/c/mouseSniffer.bat) .You can use it as a reference and check the [low level keyboard hook](https://blogs.msdn.microsoft.com/toub/2006/05/03/low-level-keyboard-hook-in-c/) to create key logger. – npocmaka Jul 27 '16 at 12:51

2 Answers2

0

The answer is simple:

    @echo off
    set /p answ1=Get user input1
    set /p answ2=Get User input2
    echo %answ1% and %answ2%>>log.txt
    notepad log.txt
    set /p "var=<log.txt"
    type log.txt
Michael Mulvey
  • 131
  • 1
  • 9
0

Even if you redirect your .bat file to a file, you can output to the screen with >con.

Execute the following script with test.bat >test.out. It will prompt you for an input on the screen.

timeout -t 2
>con set /p "var1=Prompt1: "
ipconfig
>con set /p "var2=Prompt2: "
echo %var1% %var2%
>con echo %var1% %var2%
exit /b
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Stephan
  • 53,940
  • 10
  • 58
  • 91