2

I would like to use SVN commands in my PowerShell script.

I know I need to declare the SVN executable as a variable, but afterwards I want to commit a file which I have declared as a variable and the commit message I would like to give is specified in a file.

$svnExe = "C:\Program Files\TortoiseSVN\bin\svn.exe"
$myFile = "C:\xx\file.txt"
$commitMsg = "C:\xx\msg.txt" 

$myFile is already a versioned file, $commitMsg is not and will also not be a versioned file.

From command-line this works:

svn commit -F C:\xx\msg.txt C:\xx\file.txt

But how would I do this using PowerShell?

1 Answer 1

7

Svn works the same way in PowerShell as it does in a Command Prompt. If you define a variable with the full path to the executable you need to run it via the call operator (&), though, because otherwise PowerShell would simply echo the string and be confused about the rest of the commandline.

$svn = 'C:\Program Files\TortoiseSVN\bin\svn.exe'
$myFile = 'C:\xx\file.txt'
$commitMsg = 'C:\xx\msg.txt'

& $svn commit -F $commitMsg $myFile

If you add the Svn directory to your path environment variable you can just invoke the executable directly:

$env:PATH += ';C:\Program Files\TortoiseSVN\bin'

...

svn.exe commit -F $commitMsg $myFile

Another option would be to define an alias for the executable:

New-Alias -Name svn -Value 'C:\Program Files\TortoiseSVN\bin\svn.exe'

...

svn commit -F $commitMsg $myFile
Sign up to request clarification or add additional context in comments.

4 Comments

I tried the first suggestion you made. And find out that it need to be: $svnExe = 'C:\Program Files\TortoiseSVN\bin\svn.exe' $myFile = 'C:\xx\file.txt' $commitMsg = 'C:\xx\msg.txt' & $svnExe commit -F $commitMsg $myFile But afterwards I got the following problem: svn: E205008: Log message contains a zero byte At line:6 char:2 + & <<<< $svnExe commit -F $commitMsg $myFile + CategoryInfo : NotSpecified: (svn: E205008: L...ins a zero byte:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError
Any idea how I solve the <svn: E205008: Log message contains a zero byte> issue?
@tommy2479 You saved msg.txt in Unicode format. Save the file in ANSI format and the error will disappear.
this really helped me out thnx!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.