我正在编写一个执行Powershell脚本的批处理文件,该脚本在某一时刻将具有UNC路径的项作为属性循环并Get-ChildItem在这些路径上使用.在最小版本中,这是我的脚本中发生的事情:
Master.bat
powershell -ExecutionPolicy ByPass -File "Slave.ps1"
Run Code Online (Sandbox Code Playgroud)
Slave.ps1
$foo = @{Name = "Foo"}
$foo.Path = "\\remote-server\foothing"
$bar = @{Name = "Bar"}
$bar.Path = "\\remote-server\barthing"
@( $foo, $bar ) | ForEach-Object {
$item = Get-ChildItem $_.Path
# Do things with item
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当我运行Master.bat时,它会因为Get-ChildItem错误而失败
get-childitem : Cannot find path '\\remote-server\foothing' because it does not exist.
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用Powershell直接运行Slave.ps1文件,它似乎完全正常.为什么只有在运行Master.bat文件时才会发生这种情况?
我尝试过的事情
FileSystem::提供商之前添加UNC路径http://powershell.org/wp/2014/02/20/powershell-gotcha-unc-paths-and-providers/-literalPath参数而不是plain -path参数Get-ChildItemGet-ChildItem \\remote-server\foothing在PowerShell中运行并成功验证与远程服务器的连接我刚刚开始使用Angular JS将我的模型绑定到许多输入字段.我的型号包括一个电话号码,格式为单个字符串:"1234567890".
function Ctrl($scope) {
$scope.phone = "1234567890";
}
Run Code Online (Sandbox Code Playgroud)
我想有三个输入字段与电话号码的相关部分相关联(区号,三位数,四位数).
<div ng-controller="Ctrl">
(<input type="text" maxlength="3">) <input type="text" maxlength="3"> - <input type="text" maxlength="4">
</div>
Run Code Online (Sandbox Code Playgroud)
但是,我无法为每个输入字段创建一个双向绑定到电话字符串的各个部分.我已经尝试了两种不同的方法:
方法1
---- JavaScript ----
function Ctrl($scope) {
$scope.phone = "1234567890";
$scope.phone1 = $scope.phone.substr(0,3);
$scope.phone2 = $scope.phone.substr(2,3);
$scope.phone3 = $scope.phone.substr(5,4);
}
---- HTML ----
<div ng-controller="Ctrl">
(<input type="text" maxlength="3" ng-model="phone1">) <input type="text" maxlength="3" ng-model="phone2"> - <input type="text" maxlength="4" ng-model="phone3">
</div>
Run Code Online (Sandbox Code Playgroud)
方法2
---- JavaScript ----
function Ctrl($scope) {
$scope.phone = "1234567890";
}
---- HTML ----
<div ng-controller="Ctrl">
(<input …Run Code Online (Sandbox Code Playgroud) 当我尝试循环切片并删除序列中的每个元素以打印剩余元素时,我会得到一些意想不到的行为,使用SliceTricks中建议的Delete方法.例如,当我尝试通过包含字母a片环,我希望可以将输出为,,的顺序:[A B C][B C][A C][A B]
方法1
package main
import "fmt"
func main() {
a := []string {"A", "B", "C"}
for i, _ := range a {
fmt.Println(append(a[:i], a[i+1:]...))
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这里的输出对我来说是令人惊讶的.它输出[B C]三次.
通过执行以下操作,我最终得到了我预期的行为:
方法2
package main
import "fmt"
func main() {
a := []string {"A", "B", "C"}
for i, _ := range a {
result := make([]string, 0)
result = append(result, a[:i]...)
result = append(result, a[i+1:]...)
fmt.Println(result)
}
} …Run Code Online (Sandbox Code Playgroud)