olitzadobric
olitzadobric

Reputation: 11

How to log output of unfinished / non-responding / hanging command in win7?

I want redirect console output of a command.
The thing is the command hangs midway (more or less) and even though it outputs to console the logfile is empty. I have also tried wtee.exe like so: com.exe | %pat%wtee.exe log.txt but it does not work.I need something that dumps the console in realtime. I'm open to pretty much any solution including c++ and powershell csript etc.

For the record i need it to post some verbose output ( https://superuser.com/questions/564468/how-can-i-store-encfs6-xml-in-another-location-and-still-make-it-detectable )

Thanks in advance

UPDATE:

Wohoo it works.
Apparently i have to delete the logfile before i run the batch script + i had to redirect stderr to stdout before piping to wtee.exe like so:

mycommand.exe  2>&1  | wtee.exe %abspath%log.txt

if i use

mycommand.exe  2>&1  | wtee.exe -a %abspath%log.txt 

then i do not have to delete the file every time.
Interesting idea the one with baretail but there is no need for it now. the stream is sent both to the console and to the log file.

Thanks a bunch

UPDATE2: i also used the gnuwin32 tag since tee and wtee are pretty much the same and so this applies to tee.exe, i think!

Upvotes: 1

Views: 2330

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

How exactly does it 'not work'? What happens if you redirect STDOUT and STDERR to a file (command >log.txt 2>&1)? Do you still get output on the console? If so, the command doesn't write to STDOUT, so tee (or wtee for that matter) doesn't get any input, because the pipe connects STDOUT of command with STDIN of tee. In that case try redirecting the handles 3-9 until you find the handle that the command writes to. Example:

command 3>log.txt

You can compensate for the missing console output by displaying the log file in a pager (e.g. baretail).

Once you found the handle you can redirect it to STDOUT and then pipe it into tee:

command 5>&1 | tee log.txt

Upvotes: 0

Related Questions