AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 555439
Accepted
Marcel Janus
Marcel Janus
Asked: 2013-11-17 07:17:51 +0800 CST2013-11-17 07:17:51 +0800 CST 2013-11-17 07:17:51 +0800 CST

在 PowerShell 中将带有变量的参数传递给本机应用程序

  • 772

这是我的部署自动化脚本的一部分:

$SVNEXE = "$env:ProgramFiles\TortoiseSVN\bin\svn.exe"
foreach ($element in $commandstoken) {
#$exportfile = [System.Web.HttpUtility]::UrlPathDecode($StreamServe5RepoURI + $commandstoken[$a])
$exportfile = ($StreamServe5RepoURI + $commandstoken[$a])
$SVNRevision = $commandstoken[$a+1]
[string]$SVNCommand = "export -r $SVNRevision --force"
Write-Host -ForegroundColor Red $SVNCommand
Write-Host -ForegroundColor Red $SVNCommand $exportfile
&"$SVNEXE" $SVNCommand $exportfile "C:\Temp\__foo\export"
$a = $a+2
}

我想将$SVNCommand变量传递给 svn.exe,但 svn.exe 抛出错误:svn.exe : Unknown subcommand: 'export -r 2384 --force'
据我所知,变量扩展正在工作,所以我不明白为什么会svn.exe抛出这个错误。

powershell
  • 2 2 个回答
  • 6046 Views

2 个回答

  • Voted
  1. Petter H
    2013-11-17T07:57:28+08:002013-11-17T07:57:28+08:00

    该错误Unknown subcommand: 'export -r 2384 --force'表明调用运算符将 'export -r 2384 --force''export -r 2384 --force'​​其视为单个参数(来自 & 调用运算符上的 technet):

    当外部命令有很多参数或者参数或路径中有空格时,事情会变得很棘手!使用空格,您必须嵌套引号,结果并不总是很清楚!

    在您的情况下,您可以执行类似该页面上建议的操作:

     $SVNcommand = @('export', '-r', $SVNRevieion, "--force", $exportfile, "C:\Temp\__foo\export") 
    

    并使用这样的所有参数调用:

    &"$SVNEXE" $SVNCommand 
    
    • 6
  2. Best Answer
    Marcel Janus
    2013-11-19T02:38:05+08:002013-11-19T02:38:05+08:00

    我让它工作的唯一方法是将每个参数保存在一个单独的变量中:

    $arg1 = 'export', '-r'
    $arg2 = $SVNRevision
    $arg3 = '--force'
    $arg4 = $exportfile
    $arg5 = 'C:\Temp\__foo\export\'
    &"$SVNEXE" $arg1 $arg2 $arg3 $arg4 $arg5
    

    这似乎实际上是错误执行需要引号和变量的命令实际上是不可能的

    • 1

相关问题

  • 资源锁和电源外壳

  • 脚本 - 如何断开远程桌面会话?

  • 如何限制向通讯组发送到外部地址?

  • Powershell对值与数组的作用不同?

  • Windows Powershell Vim 键绑定

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve