2

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?

sbi
  • 463
  • 2
  • 4
  • 12

3 Answers3

2

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

Mike Shepard
  • 748
  • 3
  • 7
  • 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
  • The -encoding parameter was added to set-content in v2 – Mike Shepard Aug 24 '12 at 20:19
  • Mhmm. I thought I _am_ using PS2, and `gh sc` didn't reveal this. Oh well, I got it running. Thanks for sharing your wisdom with me! If not someone comes along shortly with an answer how to do this without a temp file, I'm going to have to accept yours. – sbi Aug 25 '12 at 09:25
1

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.

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
  • 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
0

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
Dan
  • 15,430
  • 1
  • 36
  • 67
  • 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