【发布时间】:2020-05-21 20:01:21
【问题描述】:
我正在尝试从 Power Shell 的容器内部运行可执行文件,并收到一条错误消息,提示无法找到它。但是,我已经确认它的目录在 Path 中,并且可执行文件在我期望的位置。我错过了什么?
PS C:\work\some_project> docker run -it --rm --name="iar_build" iar_env
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\docker_work> IarBuild.exe
IarBuild.exe : The term 'IarBuild.exe' 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 and try again.
At line:1 char:1
+ IarBuild.exe
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (IarBuild.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\docker_work> $Env:Path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\
OpenSSH\;C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\IAR Systems\Embedded
Workbench 8.1\common\bin"
PS C:\docker_work> ls 'C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.1\common\bin\IarBuild.exe'
Directory: C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.1\common\bin
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 9/1/2018 4:09 AM 724992 IarBuild.exe
PS C:\docker_work>
我的 docker 文件包含以下内容:
...
# Add the IAR common\bin\ folder to the image's PATH
RUN setx path \
"%path%;C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.1\common\bin\"
...
CMD [ "powershell.exe", "-executionpolicy" , "Unrestricted" ]
【问题讨论】:
-
SETX将变量写入注册表HKCU\Environment中的主环境,并且不影响当前的 CMD 或 PowerShell 会话(来自setx /?的信息)。请注意,我不知道 docker 的RUN setx path …。$Env:Path和后续ls的输出似乎有点令人困惑,因为$Env:Path中的尾随双引号? -
如果我使用 cmd 而不是 powershell,例如
CMD [ "cmd" ]我可以调用 IarBuild.exe -
PowerShell 中的
where.exe IarBuild.exe怎么样? -
PS C:\docker_work> where.exe IarBuild.exe INFO: Could not find files for the given pattern(s). -
$Env:Path中的尾随双引号是错字吗?
标签: windows powershell docker docker-for-windows