2015-06-17 156 views
1

我们有一个在unix环境中正常执行的脚本。 以下是从脚本行:Get-Content命令未被识别

command => 'use/bin/tail -n 1 %{path} | grep --silent -F "%{message}" && rm -f {path}' 

当在PowerShell中运行时,use/bin/tail路径显然是不认可的。作为一种替代我尝试这样做:

command => 'Get-Content -n 1 %{path} -Tail | grep --silent -F "%{message}" && rm -f {path}' 

然而,当从PowerShell命令行运行本身时Get-Content一经确认,不能识别从脚本中运行时。 这是错误信息:

'Get-Content'不被识别为内部或外部命令,可操作程序或批处理文件。

在PowerShell中运行脚本时,复制unix tail命令的正确方法是什么?

回答

5

错误您收到:

%1 is not recognized as an internal or external command, operable program or batch file. 

cmd.exe标准错误,未powershell.exe

enter image description here

你的命令没有得到通过PowerShell主机执行,而是由普通命令提示符 - PowerShell会提到在“找不到命令”的情况下调用“cmdlet,函数,脚本文件或可操作程序”的可能性(有目的地拼写错误的Get-Content演示):

enter image description here

您还需要编辑命令的更多一点,对PowerShell来理解它,在管道中的第一个语句应该是:

Get-Content $Path -Tail 1 

假设$Path包含您正在拖尾的文件的路径。

+0

谢谢。该脚本正在从Powershell命令行运行 - 需要执行哪些操作才能由powershell主机执行,而不是命令提示符? – user1052610

+0

你可以发布一个截图吗?我觉得很难相信?! –

+0

@ user1052610不确定最后一部分。你是否在等待某个消息发生,然后删除该文件一旦发生? –