0

I made this simple .bat batch-file containing

@echo off
set log=mainLog.txt
cd /d F:/Project/Python
echo [%TIME%]starting main.py >%log%
python main.py >> %log%

the command prompt is successfully redirect main.py output to the log file, but doesn't show it on prompt screen. So I change it to:

python main.py 2>> %log% 

this will show the output of main.py to the prompt screen but not redirecting to log file. I've already tried to use:

python main.py 2>> %log% 1>> %log%

but this give me:

The Process cannot access the file because it is being used by another process

Let's assume that my main.py containing:

for i in range(10):
    print("this is line no. {}".format(i))

Is there any idea how this could be done?

bastelflp
  • 9,362
  • 7
  • 32
  • 67
Wowotek
  • 55
  • 2
  • 9
  • 2
    Possible duplicate of [Displaying Windows command prompt output and redirecting it to a file](https://stackoverflow.com/questions/796476/displaying-windows-command-prompt-output-and-redirecting-it-to-a-file) –  Nov 18 '17 at 05:37
  • You are essentially wanting an implementation of the `TEE` command on Unix systems. Windows does not have a native command that does that. If you want that functionality you will have to download a third party `TEE` program that works on Windows. – Squashman Nov 18 '17 at 05:38

1 Answers1

1

Use type to call and display the file(text only) in prompt

read more how to use type - @SS64 - Type Command.

(for example)

This script outputs to a log but you need to call the output log to be displayed on prompt.

@echo off
::script file path - x:\myproject\xyz.py
::script filename if batch runs in same directory - xyz.py
set myscrpt="xyz.py"

::Log file path
set pylog="myscriptlog.log"

::Python Path
pushd C:\Python27

::script output to log
echo ----------log-start---------- >%pylog%
%myscrpt% >>%pylog%
echo ----------log-end---------- >>%pylog%
cls

::Display log output in prompt
type %pylog%
pause>nul
exit
Gourav
  • 116
  • 1
  • 6