在同一台机器上安装它们时是否有任何限制,或者我需要注意的事项?
在 AzureDevOps 管道中,我有用 Bash/Powershell 脚本编写的任务。
如果我选择使用Inline scrpit,我可以直接使用预定义的变量,例如
cd $(Build.SourcesDirectory)
Run Code Online (Sandbox Code Playgroud)
但是,如果我选择使用文件路径来调用脚本,则无法直接在脚本文件中使用预定义变量。我必须将预定义变量传递给任务定义中的环境变量,如下例所示,这样我就可以在 script.sh 中使用 $SourceDirectoy,

有没有更好的方法在脚本中直接调用预定义变量?
我编写了一个非常简单的 powershell 脚本来将 json 字符串发布到服务器。当我执行脚本时遇到一个奇怪的问题。
服务器位于我们的内网内,所有内网服务器的防火墙均已禁用。
我尝试在不同的地方执行脚本:
在我自己的计算机上的第三方命令提示符应用程序中启动 powershell.exe
Citrix seesion 中的 Powershell 窗口(Windows 10、powershel 5)
我检查了所有 6 个地方都有 ExecutionPolicy“RemoteSigned”,
但是,我只能成功执行最后 3 个位置的脚本,
在前 3 位,我收到错误
Invoke-RestMethod : Unable to connect to the remote server
At F:\Temp\test.ps1:46 char:9
+ $resp = Invoke-RestMethod -Method POST -Body $result ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod],
WebException
+ FullyQualifiedErrorId : System.Net.WebException,Microsoft.PowerShell.Com
mands.InvokeRestMethodCommand
Run Code Online (Sandbox Code Playgroud)
此外,我也尝试过Invoke-WebRequest …
测试代码(test.ps1):
Param(
[string]$content = $null,
[switch]$flag = $false
)
Write-Host $content
Run Code Online (Sandbox Code Playgroud)
输出:
PS C:\Users\powershell> .\test.ps1 PS C:\Users\powershell> .\test.ps1 -flag $true True PS C:\Users\powershell> .\test.ps1 -flag $false False PS C:\Users\powershell> .\test.ps1 -flag $true -content "lalala" lalala
无论我设置$content为$null,或者""没有任何默认值,输出都是相同的.
那么为什么$content要从中获取价值$flag呢?
在 OSX 中,我打开 bash 终端并进入 PowerShell 控制台。在我的 PowerShell 脚本中,我想打开另一个 PowerShell 控制台并在那里执行 PowerShell 脚本。
在Windows下,我会做
Invoke-Expression ('cmd /c start powershell -Command test.ps1')
Run Code Online (Sandbox Code Playgroud)
我怎样才能在 OSX 中做同样的事情?
我尝试在 Powershell 中执行 python 脚本,但出现此错误。脚本本身是正确的,我可以在 CMD 中执行相同的命令。
那么我应该在powershell中写什么?
"C:\Program Files\Python36\python.exe" .\setup.py install
At line:1 char:40
+ "C:\Program Files\Python36\python.exe" .\setup.py install
+ ~~~~~~~~~~
Unexpected token '.\setup.py' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Run Code Online (Sandbox Code Playgroud) 我找不到解决 pep8 E502 和 W504 的好方法
我有这样的代码
if (foo(a, b) or
foo1(c, d) or
foo2(e, f) ) and
foo3(g, h):
Run Code Online (Sandbox Code Playgroud)
如果我这样写,我就会抱怨我违反了“二元运算符后的 W504 换行符”。
但是,如果我在二元运算符之后添加换行符,那么我会抱怨我违反了“ E502 括号之间的反斜杠是多余的”
如果我不能把它们变成一行,我应该如何编写代码?
我有一个PowerShell脚本,它有两个参数,第一个是字符串,第二个是字符串数组。
我想从我的 python 代码中调用这个 PowerShell 脚本。如何将数组类型参数传递给PowerShell?
如果我写这样的东西:
subprocess.run(['powershell.exe', 'script.ps1', 'arg1', '@("str1", "str2")'])
Run Code Online (Sandbox Code Playgroud)
Powershell 认为 '@("str1", "str2")' 是一个字符串,而不是一个数组。
编辑 我找到了解决方法
subprocess.run(['powershell.exe', 'script.ps1 arg1 @("str1", "str2")'])
Run Code Online (Sandbox Code Playgroud)
它看起来不漂亮,但是有效。这样,我就无法使用-File之后powershell.exe