小编Jon*_*han的帖子

在UNC路径上运行Get-ChildItem在Powershell中运行,但在批处理文件中运行的Powershell中不运行

我正在编写一个执行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文件时才会发生这种情况?

我尝试过的事情

powershell cmd unc batch-file

22
推荐指数
2
解决办法
5万
查看次数

如何在Angular中为一个模型使用字符串的一部分?

我刚刚开始使用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)

javascript angularjs

4
推荐指数
1
解决办法
2914
查看次数

删除切片中的每个元素

当我尝试循环切片并删除序列中的每个元素以打印剩余元素时,我会得到一些意想不到的行为,使用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)

go

1
推荐指数
1
解决办法
135
查看次数

标签 统计

angularjs ×1

batch-file ×1

cmd ×1

go ×1

javascript ×1

powershell ×1

unc ×1