Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is a part from my deployment automation script:

$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

I want to pass the svn.exe the $SVNCommand variable but the svn.exe throws an error: svn.exe : Unknown subcommand: 'export -r 2384 --force'
As far as I can see the variable expansion is working so I can not understand why the svn.exe throws this error.

share|improve this question

The error Unknown subcommand: 'export -r 2384 --force' suggests that call operator treats 'export -r 2384 --force''export -r 2384 --force' this like a single argument (from technet on the & call operator):

Things can get tricky when an external command has a lot of parameters or there are spaces in the arguments or paths! With spaces you have to nest Quotation marks and the result it is not always clear!

In your case, you could do something like like suggested on that page:

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

And invoke with all arguments like this:

&"$SVNEXE" $SVNCommand 
share|improve this answer
Thank you for your help. I just tried as suggest but the command still fails. If print out the $SVNCommand with Write-Host everything looks good. I can even copy and paste the command line to the CMD where everything works as expected. – Marcel Janus Nov 16 '13 at 16:57
Yes, that has to do with the way write-host prints out arrays. To the call operator & what you pass in your powershell script maps to command arguments, so the issue you face relates to how the svn.exe interprets the arguments. What error do you get after trying the solution I suggested? – Petter H Nov 16 '13 at 17:06
Thx for the fast reply. Here is the error: export -r 2384 --force C:\Temp__foo\export svn.exe : Unknown subcommand: 'export -r 2384 --force C:\Temp__foo\export' In C:\Temp__foo\SVN Export.ps1:16 Zeichen:1 + &"$SVNEXE" $SVNCommand + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Unknown subcomm...p__foo\export':String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError Type 'svn help' for usage. – Marcel Janus Nov 16 '13 at 17:08
Try building your command like this & "$SVNexe" @("export", "-r") and see where the errors no longer makes sense for what your're trying to do! – Petter H Nov 16 '13 at 17:50
up vote 1 down vote accepted

The only way I got it to work is to hold every parameter in a separate variable:

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

This seems actually bug Executing commands which require quotes and variables is practically impossible

share|improve this answer
Thanks for this, it took way too long to figure out how to do such a simple thing, batch scripts are much easier for something like this. – ToastyMallows Jun 28 at 1:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.