【问题标题】:Additional Spaces Inserted into Powershell Program at Runtime在运行时插入到 Powershell 程序中的额外空格
【发布时间】:2015-03-13 22:52:11
【问题描述】:

我遇到了一个“古怪”的 PowerShell 问题,希望有人能帮我解决。这可能不是真正的 PowerShell 问题,但我已经两次使用 PowerShell。

今天,我下载了 PSUnit。我遵循了安装说明,其中包括将 profile.ps1 复制到我的 PowerShell 配置文件目录中。文件的第一行是:

$PSUnitPath = "D:\Data\PSUnit"

完成安装后,当我在 PowerShell ISE 中打开我的 PSUnit 测试时,我收到以下错误:

The term ' $ P S U n i t P a t h ' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct an
d try again.
At C:\Users\sfhostingadmin.SCRUMDOMAIN\Documents\WindowsPowerShell\profile.ps1:3 char:24
+  $ P S U n i t P a t h  <<<<   =   " D : \ D a t a \ P S U n i t "   # M o d i f y   t h i s   p a t h   t o   m a t c h   y o u r   l o c a l   P o w e r S h e l l   i n s t a l l a t i o n   p a t h 
    + CategoryInfo          : ObjectNotFound: ( $ P S U n i t P a t h :String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

注意,它在所有字母之间插入了一个空格。当我在文本编辑器中打开文件时,多余的空格不存在。

我在简单地打开 Powershell 命令窗口时也收到此错误,即不涉及 ISE。

我认为这不是 PSUnit 问题。我以前在另一个不涉及 PSUnit 的 PowerShell 程序上遇到过这种情况。我当时解决它的唯一方法是打开一个新文件,然后重新键入 PowerShell 程序。

【问题讨论】:

  • 您是否检查过这是否是 Unicode 与 Ascii 的问题?

标签: powershell


【解决方案1】:

这是一个编码问题。该文件是双字节字符编码(例如,UCS-2 大端),但 ISE 将其解释为单字节字符(例如,UTF-8)。这通常发生在缺少字节顺序标记 (BOM) 或编辑器或程序不理解两字节编码时。

在 Notepad++ 中打开文件,然后使用编码菜单将其更改为 UTF-8。没有 BOM 的 UTF-8 也可以。

【讨论】:

  • 谢谢,感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-17
相关资源
最近更新 更多