Get-ChildItem
如果它仅找到一项,则似乎返回单个对象,而不是一个对象的数组。例如,这返回5:
$files = Get-ChildItem -Filter "e*.txt"
$files.length
Run Code Online (Sandbox Code Playgroud)
但是以下内容应返回1但返回61321:
$files = Get-ChildItem -Filter "exact.txt"
$files.length
Run Code Online (Sandbox Code Playgroud)
61321是文件确切.txt的大小(以字节为单位)。
我们如何持续检查是否找到文件?
我有一个 vuetiful 组件,它应该只显示一个对话框。不幸的是,一个邪恶的覆盖物已经接管了 domverse。我如何克服半透明黑暗的力量?
Vue.component('step-form', {
data: function() {
return {
dialog: false
}
},
methods: {
showDialog() {
this.dialog=!this.dialog;
}
},
template: `
<v-dialog v-model="dialog" persistent max-width="600px">
Help, I'm hidden behind this evil "overlay"!
</v-dialog>
`
});
Run Code Online (Sandbox Code Playgroud)
我正在编写调用其他 PowerShell 脚本的 PowerShell 脚本,& .\other\script.ps1
但我认为反斜杠\
是 Windows 的东西,我希望我的脚本能够跨平台工作。
我注意到 Windows 中的 PowerShell 确实接受,& ./other/script.ps1
但这可能是偶然的。PowerShell 总是会将我的反斜杠转换为主机平台吗?
在 PowerShell 中跨平台处理路径分隔符的最佳方法是什么?
我有一个可以响应的后端服务,/
但我希望它在入口路由上运行myhost.com/overview
。无论我尝试哪种配置,traefik 都不会删除路径/overview
- 我可以看到后端正在获取/overview
.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: registry-ingress
namespace: ingress
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myhost.com
http:
paths:
- path: /overview
pathType: Prefix
backend:
service:
name: overview
port:
number: 8079
Run Code Online (Sandbox Code Playgroud)
我尝试过几种变体:
traefik.ingress.kubernetes.io/rewrite-target: /$1
...
- path: /overview(.*)
Run Code Online (Sandbox Code Playgroud)
但这些会导致入口/overview
请求未到达后端时出现 404。
总之,我想https://myhost.com/overview/
访问后端/
。
我的 PATH 上有一个小的“dev.bat”批处理文件,我运行该文件以切换到W:\
. 这在 CMD 中可以正常工作,但在 PowerShell(或 PWSH)中运行时则不行。
从 PowerShell 运行 .bat 文件没有其他问题。
PS C:\> type C:\dev.bat
W:
CD W:\dev
PS C:\> dev.bat
me@computer C:\
> W:
me@computer W:\dev
> CD W:\dev
PS C:\> echo "Why did dev.bat not change directory??"
Why did dev.bat not change directory??
PS C:\> W:
PS W:\>
Run Code Online (Sandbox Code Playgroud)
不,cmd /c dev.bat
没有区别。
两者均见下方$a
,$s
是包含文本的字符串,"String"
但每个字符串的转换方式与ConvertTo-JSON不同。
为什么不$s | ConvertToJson
生产"String"
??
PS W:\PowerShell\powowshell> $a="String"
PS W:\PowerShell\powowshell> $a
String
PS W:\PowerShell\powowshell> $a.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS W:\PowerShell\powowshell> $a | ConvertTo-Json
"String"
PS W:\PowerShell\powowshell> $s
String
PS W:\PowerShell\powowshell> $s.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS W:\PowerShell\powowshell> $s | ConvertTo-Json
{
"value": "String",
"required": "true"
}
Run Code Online (Sandbox Code Playgroud)
$s
在parameterValue
一个.ps1
检查用Get-Help …
我正在使用 TypeScript,并且经常不得不tsc-watch
手动启动任务。根据博客 VSCode v1.30+ 可以在打开文件夹时自动运行任务,但这对我不起作用(v1.33.1) - 我打开我的文件夹但没有运行任何任务。
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"isBackground": true,
"problemMatcher": [
"$tsc"
]
},
{
"type": "typescript",
"label": "TypeScript Compiler Watcher Thingy...",
"tsconfig": "tsconfig.json",
"option": "watch",
"problemMatcher": [
"$tsc-watch"
],
"runOptions": {
"runOn": "folderOpen"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句:也试过这个扩展,它也没有启动任务。
我们看到一个奇怪的问题,块yarn
中的任何命令script
都会在yarn命令之后终止该脚本块。
steps:
- script: |
echo "*********1*********"
cd D:\my\src
echo "*********2*********"
yarn add --dev jest-junit
echo "*********3*********"
yarn test:unit --silent --ci --reporters=jest-junit
echo "*********4*********"
Run Code Online (Sandbox Code Playgroud)
将产生以下输出:
"*********1*********"
"*********2*********"
yarn add v1.16.0
[1/4] Resolving packages...
...
Done in 107.91s.
Finishing: CmdLine
Run Code Online (Sandbox Code Playgroud)
所以我们永远无法到达echo "*********3*********"
即使是像这样简单的事情:
- script: |
echo "Start"
yarn -v
echo "We never get here"
Run Code Online (Sandbox Code Playgroud)
看起来 Cmdline 任务在第一个纱线任务之后就停止了。
这是在本地 Windows Server 2016 上运行的。如果我们在 ubuntu 虚拟机上运行相同的脚本,它可以正常工作。
我希望该PublishTestResults@2
任务仅在前一个任务script
(运行单元测试)实际运行时才运行。
condition: succeededOrFailed()
thenPublishTestResults@2
运行,即使上一步没有运行 - 我认为这就是目的condition: always()
。always()
和 和有什么区别succeededOrFailed()
? # This step only runs if the previous step was successful - OK
- script: |
cd $(System.DefaultWorkingDirectory)/application/src
yarn test:unit --silent --ci --reporters=jest-junit
displayName: 'Jest Unit Tests'
env:
JEST_JUNIT_OUTPUT_DIR: $(System.DefaultWorkingDirectory)/testresults
JEST_JUNIT_OUTPUT_NAME: 'jest-junit.xml'
# This step ALWAYS runs - NO
# This step should ONLY run if the previous step RAN (success OR fail)
- task: PublishTestResults@2
displayName: …
Run Code Online (Sandbox Code Playgroud) 可以在 PowerShell 中定义脚本的输出类型。考虑myScript.ps1
:
[OutputType([String])]
param(
[string]$name
)
Run Code Online (Sandbox Code Playgroud)
以下返回String
:
(Get-Command .\myScript.ps1).OutputType.Name
Run Code Online (Sandbox Code Playgroud)
但我想指定脚本返回text/json
或text/xml
. 这样做的好方法是什么?
为 OutputType 发明类型(例如[String.JSON]
)不起作用。
powershell ×4
azure-devops ×2
arrays ×1
batch-file ×1
json ×1
reflection ×1
vscode-tasks ×1
vue.js ×1
vuetify.js ×1
yarnpkg ×1