Redian新闻
>
Powershell dot sourcing question.
avatar
Powershell dot sourcing question.# DotNet - 窗口里的风景
M7
1
I have two scripts, A.ps1 is the main function and B.ps1 has all the
functions that A.ps1 calls. Both scripts are in the same folder.
To put B into A’s scope, I tried to put the following in A.ps1
. .\B.ps1
With the above statement, or I put the path in single or double quotes, I
always get this error message:
The term '.\B.ps1' 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.
If I use the absolute path, the script runs smoothly.
. C:\Users\xyz\Desktop\B.ps1
Any clue what is wrong?
Thanks a lot!
avatar
t*s
2
解决依赖问题在PowerShell 2.0里可以用Module
可参考 http://msdn.microsoft.com/en-us/library/dd878310(v=vs.85).aspx
如果非要用dot source的话,在A.ps1里加入
$myPath = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
. $myPath/relativePathToB/B.ps1

【在 M7 的大作中提到】
: I have two scripts, A.ps1 is the main function and B.ps1 has all the
: functions that A.ps1 calls. Both scripts are in the same folder.
: To put B into A’s scope, I tried to put the following in A.ps1
: . .\B.ps1
: With the above statement, or I put the path in single or double quotes, I
: always get this error message:
: The term '.\B.ps1' 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.
: If I use the absolute path, the script runs smoothly.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。