We have script which is normally executed within a unix environment. The following is a line from the script:
command => 'use/bin/tail -n 1 %{path} | grep --silent -F "%{message}" && rm -f {path}'
When run within PowerShell, the use/bin/tail
path is obviously not recognized. As an alternative I tried this:
command => 'Get-Content -n 1 %{path} -Tail | grep --silent -F "%{message}" && rm -f {path}'
However, while Get-Content
is recognized when run from the PowerShell command line itself, it is not recognized when run from within the script.
This is the error message:
'Get-Content' is not recognized as an internal or external command, operable program or batch file.
What is the correct way to replicate the unix tail
command when running a script in PowerShell?
The error you receive:
is a standard error from
cmd.exe
, notpowershell.exe
:Your command is not getting executed by a powershell host, but by a regular command prompt - PowerShell would have mentioned the possibility of invoking a "cmdlet, function, script file or operable program" in case of "command not found" (misspelled Get-Content on purpose to demonstrate):
You'll also need to edit the command a little more, for PowerShell to make sense of it, the first statement in the pipeline would be:
assuming that
$Path
contains the path to the file you're tailing.