我尝试在 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) 有没有办法通过 Azure 模板或 Powershell 创建 cosmosDb 集合?
到目前为止,我所获得的只是 Azure CLI 的示例,但这些示例不符合我的要求。
我还想避免 Rest Calls,因为与可能的 Powershell 解决方案相比,这会带来很多开销。
我需要为 Java 设置一个系统环境变量。我目前正在使用这种方法:
setx /M JAVA_HOME "C:\Program Files (x86)\Java\jdk1.6.0_17"
Run Code Online (Sandbox Code Playgroud)
我的问题:有没有更好的(PowerShell)方法来做到这一点?
我尝试使用:
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files (x86)\Java\jdk1.6.0_17")
Run Code Online (Sandbox Code Playgroud)
但这不会产生与setx.
有没有更好的 PowerShell 方法来设置 Java 主页?
在 PowerShell 中,我有一组需要传递给函数的对象。该函数是然后循环遍历数组中的所有对象,但它似乎没有正确接受参数值。
以下面的例子为例,我传递了一个包含两个对象的数组。我希望数组的计数在函数之前和函数内都是 2,但是一旦它碰到函数,计数就是 1,而我的输入并不像预期的那样;只发现最后一个对象。
我在这里遗漏了什么,还是 PowerShell 中的错误?
### I've also tries '[object]', '[array]' and '[array[]]' as the type for '$testArr'.
function Test-PassArrayOfObjects
{
param(
[parameter(Mandatory,ValueFromPipeline)]
[object[]]$testArr
)
Write-Host "In function count: $($testArr.Count)"
$testArr | ForEach-Object { $_ }
}
$test1 = New-Object –TypeName PSObject
$test1 | Add-Member -MemberType NoteProperty -Name Test1 -Value Value1
$test2 = New-Object –TypeName PSObject
$test2 | Add-Member -MemberType NoteProperty -Name Test2 -Value Value2
$testArr = @($test1, $test2)
$testArr.GetType() | Format-Table
Write-Host "Before function …Run Code Online (Sandbox Code Playgroud) 我们如何将根本没有扩展名的文件夹中的所有文件重命名为“.something”。我已经尝试过了ren *.* *.jpeg,但没有任何效果
我正在尝试在给定域(例如 www.example.com)的虚拟主机证书存储中查找最新证书
找到任意数量的匹配证书很容易,但是我如何才能找到按到期日期(最远的未来)排序的最新证书?
我现有的代码是:
(Get-ChildItem -Path cert:\LocalMachine\WebHosting
| Where-Object {$_.Subject -match "example.com"}).Thumbprint;
Run Code Online (Sandbox Code Playgroud)
然而,这有时会返回两个证书,因为通常之前的证书(在续订之前)必须在证书存储中保留一小段时间。
我正在尝试使用 PowerShell 运行 python 脚本。在那个 python 脚本中,我尝试使用包含双引号和空格的命令行参数,但它无法正常工作。我怀疑这是 PowerShell 的问题。
(简化的)python 脚本如下所示:
import sys
print(sys.argv[1])
Run Code Online (Sandbox Code Playgroud)
以下调用和输出显示了问题
python script.py --arg=foo
--arg=foo
python script.py --arg='\"foo\"'
--arg="foo"
python script.py --arg='\"fo o\"'
--arg="fo
Run Code Online (Sandbox Code Playgroud)
但我最终需要的是
--arg="fo o"
Run Code Online (Sandbox Code Playgroud)
它会在空格之后去除所有内容。我在 Linux bash 中测试了相同的脚本(在 foo 周围使用双引号)。这似乎不是 python 问题,而是 PowerShell 问题,有人可以帮助我吗?最后我想要一个完整的 JSON-String 作为参数。
我开始在 PowerShell 中制作一些脚本,但我遇到了问题。
我想计算一下某人通过键盘引入的字符数。我正在尝试这个:
write-host $FC
$numcar = $FC.Count
Run Code Online (Sandbox Code Playgroud)
但它总是返回 1。
有人能帮我吗?
我正在执行:
systeminfo | ConvertTo-Json
"Host Name: namehere",
"OS Name: Microsoft Windows 10 Enterprise",
...
Run Code Online (Sandbox Code Playgroud)
但是我需要
"Host Name": "namehere",
"OS Name": "Microsoft Windows 10 Enterprise",
...
Run Code Online (Sandbox Code Playgroud)
以下命令给出了类似的问题
systeminfo | ConvertTo-Xml -As String
<?xml version="1.0" encoding="utf-8"?>
<Objects>
<Object Type="System.String"></Object>
<Object Type="System.String">Host Name: namehere</Object>
<Object Type="System.String">OS Name: Microsoft Windows 10 Enterprise</Object> "
Run Code Online (Sandbox Code Playgroud)
但我需要类似的东西:
<?xml version="1.0" encoding="utf-8"?>
<HostName>namehere</HostName>
<OSName>Microsoft Windows 10 Enterprise</OSName>
...
Run Code Online (Sandbox Code Playgroud) 如何在 Windows 上为 Linux 编译 go 文件/项目?
在 Linux 上,它应该可以通过 one-liner 实现:
GOOS=windows go build -o filename.exe codefile.go
Run Code Online (Sandbox Code Playgroud)
我通过 Powershell 尝试了类似的东西,但在我的 Linux 服务器(Ubuntu 16.04 amd64)上只出现一个错误:
-bash: ./gotest: 无法执行二进制文件:Exec 格式错误”。
我在 Powershell 中尝试使用用户 Env-vars for GOOS = linuxandGOARCH = amd64和 via set GOOS = linux,但我对 Powershell 了解不够 - go build 命令运行时没有错误并生成文件。
任何人都可以使用 go-1.10 通过 Powershell(或 cmd)(通过 VS Code)解释 Windows(10 1709 x64)上的一般操作方法吗?
powershell ×10
json ×2
python ×2
azure ×1
cmd ×1
command-line ×1
count ×1
function ×1
go ×1
parameters ×1
scripting ×1
windows ×1
xml ×1