0

I can open a cmd window and start a tail by entering something like this:

tail -f C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\sites.log

This is probably a stupid question, but how do I do this in a batch file?

It should be easy but it's not working - I have tried a couple variations and no success. Can anyone tell me what I am doing wrong here?

ECHO OFF
CD C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\
cmd
tail -f sites.log

I've also tried:

ECHO OFF
start cmd tail -f C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\sites.log

(am using Win7 Ultimate, on a 64-bit machine, if that has any bearing)

1 Answer 1

1

I can beat that. Just make a shortcut and put this in the target field:

cmd.exe /K tail.exe "C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\sites.log"

It's a one liner so no need for a BATCH file.

If you did want a script file, then do this:

@echo off
tail.exe "C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\sites.log"

or just

@tail.exe "C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\sites.log"

since it's only 1 line.

I'm going to guess that the problem you had was that you named your BATCH file tail.bat. Then inside it you just used tail C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\sites.log. This caused your script to reference itself because DOS is going to look in the current dir first. It would've ended up calling tail.bat C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\sites.log over and over again.

Update

If you want the window to stay open then you have a few options. You can use the pause command:

@tail.exe "C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\sites.log"
@pause

or you can lauch a new shell inside the terminal which stays open after it finishes. This will cause the parent shell to remain open as well as the terminal itself:

@cmd.exe /K tail.exe "C:\Oracle\WebCenter\Sites\11gR1\Sites\11.1.1.6.1\logs\sites.log"

The pause command is good if you want the window to close easily. Just press any key and it's gone. The second option is better if you typically want to run other commands after it runs.

5
  • ahh cool - thanks very much. The bat files would sort of work, I could see the windown open and show the sites.log file but then it closed itself. I tried the shortcut method though - and that works well enough. It opens in cmd and starts the tail but then has broken out into the prompt again. I can type tail -f sites.log again easily enough, but I'll admit to a certain lazy method to my morning routine. ;-)
    – Kari
    Aug 19, 2014 at 14:19
  • @Kari See my update.
    – krowe
    Aug 19, 2014 at 14:39
  • 2nd Option works. how do I accept the answer? it works, but I don't see a button to click and confirm this.
    – Kari
    Aug 19, 2014 at 17:16
  • superuser.com/help/someone-answers
    – krowe
    Aug 20, 2014 at 3:23
  • I clicked the check icon under the answer - is that the one?
    – Kari
    Aug 20, 2014 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .