gpt4 book ai didi

电源外壳 |无法执行带有空格字符的命令

转载 作者:行者123 更新时间:2023-12-02 23:04:24 24 4
gpt4 key购买 nike

谁能向我解释一下原因:

iex "C:\Program Files\test\test.exe"

返回:

C:\Program : The term 'C:\Program' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + C:\Program Files\test\test.exe + ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Program:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException


我尝试过多种不同的方式来使其发挥作用:

  • 将文本换行到 ()
  • 将字符串放入变量中并将其作为变量传递
  • 使用单引号
  • 使用双引号

我不知道我还能如何让它意识到必须运行整个字符串,而不仅仅是第一个单词。


后回答示例

问题已得到解答。这是我试图做的事情:

$tool = "C:\Windows\System32\cmd.exe"
$param = "/c ping google.com -n 1"
$test = & $tool $param
Write-Host $test

事实证明,在这种情况下,带有 & 的行不能与双引号 "" 一起使用,并且实际上在没有双引号的情况下也可以工作。我认为这与涉及参数/参数有关。

最佳答案

& 运算符与引号一起使用:

& "C:\Program Files\test\test.exe"

来自about_operators帮助:

  & Call operator
Runs a command, script, or script block. The call operator, also known as
the "invocation operator," lets you run commands that are stored in
variables and represented by strings. Because the call operator does not
parse the command, it cannot interpret command parameters.

C:\PS> $c = "get-executionpolicy"
C:\PS> $c
get-executionpolicy

C:\PS> & $c
AllSigned

关于电源外壳 |无法执行带有空格字符的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21668926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com