leeand00
leeand00

Reputation: 26402

Why can't I tail a log in powershell when I run it from the run Window?

If I open a Power Shell window and run the following command it works fine...

get-content -Path C:\Users\user\AppData\Local\Temp\90\tmpDF49.tmp -wait

But if I open the run menu (WINKEY+R) and then run it like this:

powershell -command 'get-content -Path C:\Users\user\AppData\Local\Temp\90\tmpDF49.tmp -wait'

it opens a powershell window and then just closes...

I've also tried the same thing from a powershell script and it just closes up...just like with the run menu:

[Diagnostics.Process]::Start("powershell.exe", "-command `"get-content -Path $($tmpFile) -wait`"")

Shouldn't it keep waiting and trying to tail the log?

Upvotes: 1

Views: 148

Answers (1)

AdminOfThings
AdminOfThings

Reputation: 25031

You need to run the following from the run line:

powershell -NoExit -command "Get-Content -Path C:\Users\user\AppData\Local\Temp\90\tmpDF49.tmp -wait"

The -command switch is designed to run the provided command and exit unless -NoExit is specified. -NoExit must come before the -command parameter by design as well.

Running PowerShell.exe -Help will divulge this information. I have been told that not all of the information is accurate, but the statements above appear to be.

Upvotes: 3

Related Questions