Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following line in a script:

svn propset svn:externals $newExternals $path

Now for the first time $newExternals is a multi-line string (there are several svn:external properties) and svn barks at me in a way that seems to indicate that it cannot deal with the argument.

Can I not pass a multi-line string to a program I invoke in PowerShell? Or is that a problem with svn not being able to parse that? Or do I need quotes? (Didn't help, but I might have screwed up something else.)


If this doesn't work, then svn would also accept a file to read the stuff from:

svn propset svn:externals -F externals.txt $path

However, this seems to fail because svn expects externals.txt to be an ASCII file (or UTF-8, I'm not sure, but I don't think it's relevant here), while PowerShell by default writes UTF-16. So what's the canonical way to pipe something into an ASCII file?


As a side question: What's the canonical way to get a path to create a temporary file at?

share|improve this question
add comment

3 Answers 3

[io.path]::GetTempFileName() will return a temporary file name (including path)

share|improve this answer
    
Thanks! But do I really have to do that? (I.e., can I really not pass a multi-line argument?) Also, How do I write ASCII/UTF-8 to such a file? –  sbi Aug 24 '12 at 13:57
    
I don't know about the multi-line argument thing, but that wouldn't be a powershell question, but a command-line issue. As far as writing the content in a particular format, you would use set-content with the encoding parameter (possible values are Unknown, String, Unicode, Byte, BigEndianUnicode, UTF8, UTF7, Ascii) –  Mike Shepard Aug 24 '12 at 14:26
    
Um. Do you perchance mean out-file, rather than set-content? –  sbi Aug 24 '12 at 14:51
    
I didn't, but you could use that as well. –  Mike Shepard Aug 24 '12 at 19:49
    
I couldn't find how to use set-content for this. It doesn't seem to have an encoding option. I used out-file now, and this works. –  sbi Aug 24 '12 at 19:58
show 2 more comments

I'm not that familiar with svn, so excuse me if the following aren't relevant... but you can certainly pass multi-line strings into Powershell, or a Powershell invoked program (assuming the invoked program supports it).

Here's one way to do it that I particularly like, from Technet Windows Powershell Tip of the Week. (Powershell 'Here-Strings`).

And here's another, from an SO answer, though I have no idea if this will work with an invoked program... just that it works natively in PowerShell.

Finally, strings (in all varieties) may also extend beyond a single line:

'Foo
bar'

If neither technique works, I'd say you've run into a limitation of svn.

share|improve this answer
    
Thanks. I do have a multi-line text in my script already, though, within that $newExternals variable. If it is common to pass this around, I suppose it's some unfortunate interaction with or limitation of svn, which I ran into. –  sbi Aug 24 '12 at 15:04
add comment

On Windows, the users temporary folder can be found using the system variable TEMP or TMP.

[Batch]
echo %TEMP%
echo %TMP%

[Powershell]
echo $env.temp
echo $env.tmp
share|improve this answer
    
Thanks, but I knew that much. The problem is that there already might hang around and externals.txt — which I might be allowed to wipe or not, have permissions to write to or not. A better solution would be to create a unique file name. –  sbi Aug 24 '12 at 13:32
add comment

Your Answer

 
discard

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.