<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cranky Bit &#187; Batch Scripting</title>
	<atom:link href="http://blog.crankybit.com/tags/microsoft/batch/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.crankybit.com</link>
	<description>Take a byte out of tech!</description>
	<lastBuildDate>Wed, 09 Mar 2011 17:23:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Redirecting Errors to a File in Windows Batch Scripts</title>
		<link>http://blog.crankybit.com/redirecting-errors-to-a-file-in-windows-batch-scripts/</link>
		<comments>http://blog.crankybit.com/redirecting-errors-to-a-file-in-windows-batch-scripts/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 17:18:31 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=344</guid>
		<description><![CDATA[In my post on Redirecting Output to a File in Windows Batch Scripts, I discussed the basics of output redirection into a text file and how this can be used for logging, including error logging by using the &#62;&#38; operator to combine the stderr and stdout streams. But Mark asked, &#8220;How do you just pipe [...]]]></description>
			<content:encoded><![CDATA[<p>In my post on <a target="_blank" href="/redirecting-output-to-a-file-in-windows-batch-scripts/">Redirecting Output to a File in Windows Batch Scripts</a>, I discussed the basics of output redirection into a text file and how this can be used for logging, including error logging by using the <strong>&gt;&amp;</strong> operator to combine the stderr and stdout streams. But Mark asked, &#8220;How do you <em>just</em> pipe stderr without joining it to stdout?&#8221; Good question!</p>
<p>So normal output redirection is handled with just the &gt; or &gt;&gt; operators (depending on whether you want to <em>overwrite</em> or <em>append</em> the target file), like so:</p>
<p><code>dir >> myfile.txt</code></p>
<p>The operator outputs the stdout stream by default. But it can be modified to output the stderr stream by just specifying that stream with the operator. Remember, stderr is stream 2. So, you would do like so:</p>
<p><code>dir 2>> myfile.txt</code></p>
<p>This would write <strong><em>only</em></strong> the error output to the file.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/redirecting-errors-to-a-file-in-windows-batch-scripts/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Separating a Large Repository</title>
		<link>http://blog.crankybit.com/separating-large-repo/</link>
		<comments>http://blog.crankybit.com/separating-large-repo/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 12:52:45 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=312</guid>
		<description><![CDATA[A few months ago, I posted an article about combining multiple Subversion repositories into one large repository. Some folks have expressed an interest in doing the opposite--separating one large repository into multiple smaller repositories. The process is not without its quirks, but it can be done. At first glance, you'd conclude the process would work [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago, I posted an article about <a href="http://blog.crankybit.com/combining-repos/">combining multiple Subversion repositories into one large repository</a>. Some folks have expressed an interest in doing the opposite--separating one large repository into multiple smaller repositories. The process is not without its quirks, but it can be done.</p>
<p>At first glance, you'd conclude the process would work much the same way: Loop through the individual directories in the large repository, create smaller repositories for each one, then dump and import the contents of each directory into its small repository.</p>
<p>The tricky part is that the Subversion dump command dumps everything in the repository, by revision. In order to pull just a single directory, you must filter a complete dump with the "svndumpfilter" command. <a href="http://allmybrain.com/2007/10/15/using-piped-svndumpfilter-commands-to-separate-an-svn-repository/" target="_blank">This blog post</a> by <a href="http://allmybrain.com/" target="_blank">AllMyBrain.com</a> basically explains how to accomplish this in Linux. I usually have to work on a Windows box on the job, so I wrote up a script to accomplish this in a Windows batch script.</p>
<p>The strategy is the same as the Linux script, though. We're going to use "svnadmin dump" the large repository, then use "svndumpfilter" to filter by just the directory we want, then "svnadmin load" the results into the newly created repository. All of this can be combined into a single statement via piping:</p>
<div class="igBar"><span id="ldos-3"><a href="#" onclick="javascript:showCodeTxt('dos-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DOS:</span>
<div id="dos-3">
<div class="dos">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svnadmin dump c:\my\large\repo\ |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svndumpfilter include MyDirectory |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svnadmin load MySmallRepo\MyDirectory </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This will make a little more sense when we look at the full script. Let's just put it out there and then go through it.</p>
<div class="igBar"><span id="ldos-4"><a href="#" onclick="javascript:showCodeTxt('dos-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DOS:</span>
<div id="dos-4">
<div class="dos">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">SET</span></a> <span style="color: #448844;">SmallRepoPath</span>=c:\SmallRepos</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">SET</span></a> <span style="color: #448844;">PathToRepo</span>=c:\BigRepo</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">SET</span></a> <span style="color: #448844;">UNCToRepo</span>=file:///c:/BigRepo</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">SET</span></a> <span style="color: #448844;">PathToChkout</span>=c:\BigRepoChkout</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mkdir %<span style="color: #448888;">PathToChkout</span>%</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn co %<span style="color: #448888;">uncToRepo</span>% %<span style="color: #448888;">PathToChkout</span>% --ignore-externals</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/dir.html"><span style="color: #b1b100; font-weight: bold;">dir</span></a> /A:D /B %<span style="color: #448888;">PathToChkout</span>%&gt; %<span style="color: #448888;">PathToChkout</span>%\dirs.tmp</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/for.html"><span style="color: #00b100; font-weight: bold;">for</span></a> /F %%i <a href="http://www.ss64.com/nt/in.html"><span style="color: #00b100; font-weight: bold;">in</span></a> <span style="color: #66cc66;">&#40;</span>%<span style="color: #448888;">PathToChkout</span>%\dirs.tmp<span style="color: #66cc66;">&#41;</span> <a href="http://www.ss64.com/nt/do.html"><span style="color: #00b100; font-weight: bold;">do</span></a> <span style="color: #66cc66;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.ss64.com/nt/if.html"><span style="color: #00b100; font-weight: bold;">if</span></a> <a href="http://www.ss64.com/nt/not.html"><span style="color: #000000; font-weight: bold;">not</span></a> %%i==.svn <span style="color: #66cc66;">&#40;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.ss64.com/nt/echo.html"><span style="color: #b1b100; font-weight: bold;">echo</span></a> Processing &quot;%%i&quot;...</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; mkdir %<span style="color: #448888;">SmallRepoPath</span>%\%%i</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; svnadmin create %<span style="color: #448888;">SmallRepoPath</span>%\%%i</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; svnadmin dump %<span style="color: #448888;">PathToRepo</span>% | svndumpfilter include %%i | svnadmin load %<span style="color: #448888;">SmallRepoPath</span>%\%%i</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">del %<span style="color: #448888;">PathToChkout</span>%\dirs.tmp</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rmdir /S /Q %<span style="color: #448888;">PathToChkout</span>% </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>First, we're setting our paths. "SmallRepoPath" will be the directory holding all of the small repositories we'll be creating. "PathToRepo" and "UNCToRepo" point to the big repository as DOS and UNC paths, respectively. "PathToChkout" points to a Subversion checkout of the large repository.</p>
<p>First, we check out the large repository with the "svn co" command. We do this just so that we can call the "dir /A:D /B" command, which says, "List just the directories in the checkout directory." We use that output to loop through each directory in the large repository.</p>
<p>Then, for each directory in the large repository, we create a corresponding small repository, then do our dump/filter/load combo. Again, we're dumping the contents of the large repository, using "svndumpfilter" to filter by directory, then loading that filtered dump into the new small repository.</p>
<p>Finally, we just do some cleanup by removing our temp files and the checkout directory.</p>
<p><strong>There <u>are</u> a few caveats with this code.</strong> </p>
<p>First, it will import <em>all</em> of the large repository's revisions into the smaller repository. There are svndumpfilter arguments to prevent this, such as --drop-empty-revs and --renumber-revs, but I found the Windows Subversion binaries to be problematic with these arguments. The end result is that you have more revision numbers than needed, but only the relevant data is actually imported into the repository, and viewing logs on just the imported directory will still obviously show revision logs related to that directory, so there's really little harm done.</p>
<p>Second, the dump/filter/load action doesn't always work on a directory that has been moved (copied/deleted) from another location within the large repository. What's worse, it won't <em>fail,</em> it just won't load any data into the small repository. To address this, use the --revision argument on the "svnadmin dump" command to do a dump starting at a revision after the move took place. Doing so will give the "svndumpfilter" command something it can work with.</p>
<p>This process is certainly more complicated to <em>explain</em>, but ultimately there's not that much more going on. Hopefully this explanation is helpful to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/separating-large-repo/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Combining Repositories Into One Large Repository</title>
		<link>http://blog.crankybit.com/combining-repos/</link>
		<comments>http://blog.crankybit.com/combining-repos/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 05:44:58 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=299</guid>
		<description><![CDATA[I keep all my projects in separate Subversion repositories. I did this because it feels a lot cleaner this way, there is less risk in the event of repository corruption, and I use corresponding Trac projects that I also wanted to keep separate from one project to the next. That said, there are advantages to [...]]]></description>
			<content:encoded><![CDATA[<p>I keep all my projects in separate Subversion repositories. I did this because it feels a lot cleaner this way, there is less risk in the event of repository corruption, and I use corresponding Trac projects that I also wanted to keep separate from one project to the next.</p>
<p>That said, there are advantages to having one single repository. No big deal, that can be done after the fact with code.</p>
<p>Here is some Windows code to combine all the repositories in a directory into a single big repository:</p>
<div class="igBar"><span id="ldos-6"><a href="#" onclick="javascript:showCodeTxt('dos-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DOS:</span>
<div id="dos-6">
<div class="dos">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">svndir</span>=c:\Test\svn</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">bigrepo</span>=c:\Test\BigRepo</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">bigrepoUNC</span>=file:///c:/Test/BigRepo</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">rev</span>=<span style="color:#800000;">0</span>:HEAD</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/echo.html"><span style="color: #b1b100; font-weight: bold;">echo</span></a> Setting up the big repository.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">rmdir /S /Q %<span style="color: #448888;">bigrepo</span>%</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mkdir %<span style="color: #448888;">bigrepo</span>%</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svnadmin create %<span style="color: #448888;">bigrepo</span>%</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/cd.html"><span style="color: #b1b100; font-weight: bold;">cd</span></a> %<span style="color: #448888;">svndir</span>%</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/dir.html"><span style="color: #b1b100; font-weight: bold;">dir</span></a> /A:D /B&gt; dirs.tmp</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/for.html"><span style="color: #00b100; font-weight: bold;">for</span></a> /F %%i <a href="http://www.ss64.com/nt/in.html"><span style="color: #00b100; font-weight: bold;">in</span></a> <span style="color: #66cc66;">&#40;</span>dirs.tmp<span style="color: #66cc66;">&#41;</span> <a href="http://www.ss64.com/nt/do.html"><span style="color: #00b100; font-weight: bold;">do</span></a> <span style="color: #66cc66;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/echo.html"><span style="color: #b1b100; font-weight: bold;">echo</span></a> Adding %<span style="color: #448888;">svnDir</span>%\%%i to the big repository:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svnadmin dump -r %<span style="color: #448888;">rev</span>% %%i &gt;&nbsp; %%i.dmp</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svn mkdir -m &quot;Making project directory %%i.&quot; --non-interactive %<span style="color: #448888;">bigrepoUNC</span>%/%%i</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">svnadmin load %<span style="color: #448888;">bigrepo</span>% --parent-<a href="http://www.ss64.com/nt/dir.html"><span style="color: #b1b100; font-weight: bold;">dir</span></a> %%i&nbsp; &lt; %%i.dmp</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">del /F /Q %%i.dmp</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">del dirs.tmp </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>There's really not much happening here; the process is simple. First, we create the new "big" repository with the <strong>svnadmin create</strong> statement. Second, we loop through the directory, processing each Subversion repository in the directory with a three-step process: <strong>(a)</strong> Dump the repository with the <strong>svnadmin dump</strong> statement into a temporary *.dmp file. <strong>(b)</strong> Explicitly add a new directory in the "big" repository for the current repository we're processing, with the <strong>svn mkdir</strong> statement. <strong>(c)</strong> Import the dump into the "big" repository with the <strong>svnadmin load</strong> statement. Really, the rest of the code is just looping, commenting, or cleanup code.</p>
<p><em><strong>What have we produced?</strong></em> As you might expect, we now have one big repository that has all of the files and commits that were in all of the smaller repositories. The big repository will maintain its own revision numbering, so the revision numbers in your smaller repositories will not match the big repository's revision numbering, although the original <em>commit dates</em> will be preserved. This can be really handy for searching or similar actions that you might do from a more global perspective.</p>
<p>However, this approach is not without its caveats. During the import process, one entire repository is imported at a time. All of a particular repository's revisions will be "grouped" together in the big repository. As a result, revision numbers in the big repository will change every time you recreate it, if there was any new activity in the repositories it contains. For instance, revision #1050 in the big repository may parallel revision #500 in Repository X, but if a commit was added to a repository that is imported before it and the big repository is recreated, that revision would now be #1051. Additionally, although all history and dates are preserved in the revisions, the big repository has commits that are not in chronological order since the import was processed by repository. This inconsistent date/commit ordering can be confusing to some repository reporting tools and may actually render those tools useless to you when they are reporting by date.</p>
<p><em><strong>Filtering by revision. </strong></em>Note that my svnadmin dump statement includes the -r argument, which specifies the beginning and ending revisions to dump. By default, I'm using "0:HEAD", which basically means "dump every revision", or "dump from the first revision to the HEAD, or latest, revision". Changing the beginning and ending revisions can be useful, especially when used with <em>dates</em> instead of actual revision numbers. For instance, you could change the value to <strong>{2007-01-01}:{2007-12-31}</strong> to only dump revisions that were committed in 2007.</p>
<p>Combining all of your smaller repositories into one big repository after the fact isn't a perfect solution, but it can be handy, and it's really easy to do when you have a script like this ready to run.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/combining-repos/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Why That Batch For Loop Isn&#8217;t Working</title>
		<link>http://blog.crankybit.com/why-that-batch-for-loop-isnt-working/</link>
		<comments>http://blog.crankybit.com/why-that-batch-for-loop-isnt-working/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 10:07:50 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/why-that-batch-for-loop-isnt-working/</guid>
		<description><![CDATA[Time for another fun foray into Windows batch scripts. Perhaps you've used the FOR /F command to loop through the contents of a file (for instance, perhaps some data that was redirected to a text file from a command). Grab a line, act on its values, and output some text and commands. Let's set this [...]]]></description>
			<content:encoded><![CDATA[<p>Time for another fun foray into Windows batch scripts. Perhaps you've used the <a href="http://www.ss64.com/nt/for_f.html" target="_blank">FOR /F</a> command to loop through the contents of a file (for instance, perhaps some data that was <a href="/redirecting-output-to-a-file-in-windows-batch-scripts/">redirected to a text file</a> from a command). Grab a line, act on its values, and output some text and commands.</p>
<p>Let's set this up. First, we have a data file named SomeAccounts.txt:</p>
<blockquote><p>Josh<br />
Mary<br />
Suzy<br />
Amanda<br />
Trisha<br />
Ben</p></blockquote>
<p>Then, we have ProcessAccounts.bat, which we want to just loop through the accounts in the text file, tell us what they are, and tell us the first letter of the account name (just to have something to do):</p>
<div class="igBar"><span id="ldos-9"><a href="#" onclick="javascript:showCodeTxt('dos-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DOS:</span>
<div id="dos-9">
<div class="dos">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">file</span>=SomeAccounts.txt</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/for.html"><span style="color: #00b100; font-weight: bold;">FOR</span></a> /F %%i <a href="http://www.ss64.com/nt/in.html"><span style="color: #00b100; font-weight: bold;">IN</span></a> <span style="color: #66cc66;">&#40;</span>%<span style="color: #448888;">file</span>%<span style="color: #66cc66;">&#41;</span> <a href="http://www.ss64.com/nt/do.html"><span style="color: #00b100; font-weight: bold;">DO</span></a> <span style="color: #66cc66;">&#40;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">username</span>=%%i</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/echo.html"><span style="color: #b1b100; font-weight: bold;">echo</span></a> My account, %<span style="color: #448888;">username</span>%, starts with %<span style="color: #448888;">username:~<span style="color:#800000;">0</span>,<span style="color:#800000;">1</span></span>%.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Except when you do this, you encounter a problem: All of the values from the FOR loop are the same! It's as if the for loop ran the proper number of times, but it just ran on the last record over and over again! See below:</p>
<blockquote><p>My account, Ben, starts with B.<br />
My account, Ben, starts with B.<br />
My account, Ben, starts with B.<br />
My account, Ben, starts with B.<br />
My account, Ben, starts with B.<br />
My account, Ben, starts with B.</p></blockquote>
<p>What's <em>actually</em> happening is the FOR loop is indeed running over every line, and setting the variables as instructed, but the results of those variables being altered isn't echoed until the FOR loop is complete, so the last value of the variable is what displays. This wouldn't be a problem if you were just using your FOR parameter, in this case <em>%%i</em>, but any variables you set while in the FOR loop, like <em>username</em>, experience this "wait until you're out of the loop" phenomenon.</p>
<p>The fix is simple enough, <u>if</u> you know about it! But I've found the solution to be a bit elusive, which is the whole point of sharing it now.</p>
<p>The key is the <a href="http://www.ss64.com/nt/setlocal.html" target="_blank">setlocal EnableDelayedExpansion</a> command. As explained at ss64.com, making this statement before your FOR loop will enable you to display variables as their value at the moment you're referencing them, or their "intermediate values" while in the middle of the FOR loop. In addition to calling the setlocal command, you then have to reference your variables with the exclamation point (!) rather than percent (%) to indicate that you want to use the intermediate value.</p>
<p>Your script will then look like this:</p>
<div class="igBar"><span id="ldos-10"><a href="#" onclick="javascript:showCodeTxt('dos-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DOS:</span>
<div id="dos-10">
<div class="dos">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/setlocal.html"><span style="color: #b1b100; font-weight: bold;">setlocal</span></a> EnableDelayedExpansion</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">file</span>=SomeAccounts.txt</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/for.html"><span style="color: #00b100; font-weight: bold;">FOR</span></a> /F %%i <a href="http://www.ss64.com/nt/in.html"><span style="color: #00b100; font-weight: bold;">IN</span></a> <span style="color: #66cc66;">&#40;</span>%<span style="color: #448888;">file</span>%<span style="color: #66cc66;">&#41;</span> <a href="http://www.ss64.com/nt/do.html"><span style="color: #00b100; font-weight: bold;">DO</span></a> <span style="color: #66cc66;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">username</span>=%%i</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.ss64.com/nt/echo.html"><span style="color: #b1b100; font-weight: bold;">echo</span></a> My account, !username!, starts with !username:~<span style="color:#800000;">0</span>,<span style="color:#800000;">1</span>!.</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>It will now happily act as desired, outputting these results:</p>
<blockquote><p>My account, Josh, starts with J.<br />
My account, Mary, starts with M.<br />
My account, Suzy, starts with S.<br />
My account, Amanda, starts with A.<br />
My account, Trisha, starts with T.<br />
My account, Ben, starts with B.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/why-that-batch-for-loop-isnt-working/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Free Command-Line Zip on Windows</title>
		<link>http://blog.crankybit.com/free-command-line-zip-on-windows/</link>
		<comments>http://blog.crankybit.com/free-command-line-zip-on-windows/#comments</comments>
		<pubDate>Fri, 15 Jun 2007 12:30:53 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/free-command-line-zip-on-windows/</guid>
		<description><![CDATA[Both Linux and Mac OS X have zip, gzip, and bzip2 command-line tools. What about Windows? If you're trying to do some scripting to automate some archiving or backup, and you want it to be a classic, WinZip-compatible .zip file, how can you do it? WinZip offers a WinZip Command Line Add-on free of charge--if [...]]]></description>
			<content:encoded><![CDATA[<p>Both Linux and Mac OS X have zip, gzip, and bzip2 command-line tools. What about Windows? If you're trying to do some scripting to automate some archiving or backup, and you want it to be a classic, WinZip-compatible .zip file, how can you do it? </p>
<p>WinZip offers a <a href="http://www.winzip.com/prodpagecl.htm">WinZip Command Line Add-on</a> free of charge--if you already own a copy of <a href="http://www.winzip.com/prodpagewz.htm">WinZip Pro</a>!</p>
<p>You shouldn't have to pay for command-line zip. And you don't have to. Enter <a href="http://www.info-zip.org/">Info-ZIP</a>. This workgroup has been maintaining free, portable, high-quality versions of zip and unzip. They have plenty of command-line arguments like you would expect from an open source project. </p>
<p>So, with this project's executables in your system path, you can write up a batch file that is executed as a Windows scheduled task. Maybe something like this:</p>
<div class="igBar"><span id="ldos-13"><a href="#" onclick="javascript:showCodeTxt('dos-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DOS:</span>
<div id="dos-13">
<div class="dos">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zip -q -S -r c:pathMyBackup.zip c:data -i@include.lst </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This will zip the c:data directory. Arguments: <strong>-q</strong> to do it quietly, <strong>-S</strong> to include system files, <strong>-r</strong> to recurse into subdirectories. Finally, use <strong>-i</strong> to point to a file that indicates the exact files to <strong>i</strong>nclude, by means of a carriage return delimited list. </p>
<p>You can alternatively use <strong>-x</strong> to specify only which files should be e<strong>x</strong>cluded. Perhaps something like this:</p>
<div class="igBar"><span id="ldos-14"><a href="#" onclick="javascript:showCodeTxt('dos-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">DOS:</span>
<div id="dos-14">
<div class="dos">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">zip -q -S -r c:pathMyBackup.zip c:data -x@exclude.lst </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The command-line flags are all optional, of course. This tool is certainly a must-have for the Windows scripter.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/free-command-line-zip-on-windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Redirecting Output to a File in Windows Batch Scripts</title>
		<link>http://blog.crankybit.com/redirecting-output-to-a-file-in-windows-batch-scripts/</link>
		<comments>http://blog.crankybit.com/redirecting-output-to-a-file-in-windows-batch-scripts/#comments</comments>
		<pubDate>Tue, 14 Nov 2006 23:06:48 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/redirecting-output-to-a-file-in-windows-batch-scripts/</guid>
		<description><![CDATA[Microsoft's Command Redirection Operators page provides the factual information on how to do redirection, but actual implementation gets a bit confusing for anything beyond command > filename.txt. Here's a rundown on how to do some useful things. I'm not going to cover every aspect of redirection, but I'll point you to the cases I find [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft's <a target="_blank" href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true">Command Redirection Operators</a> page provides the factual information on how to do redirection, but actual implementation gets a bit confusing for anything beyond command > filename.txt. Here's a rundown on how to do some useful things. I'm not going to cover every aspect of redirection, but I'll point you to the cases I find myself in most often.</p>
<p><strong>The basics. </strong>You want to generate either a log file or a file that you will be executing after you're done generating it. You'll likely be using a combination of echo commands as well as some output from a handful of commands. Welcome to the &gt; and &gt;&gt; operators. The first will send the output to a file and erase its existing contents; the second will <em>append</em> the output to the file.</p>
<p>Examples:</p>
<blockquote><p># This will send the dir command's output to a fresh file:<br />
dir &gt; myfile.txt</p>
<p># Here I will create a fresh file with an echo command,<br />
# and append the dir output to that:<br />
echo Here is a directory &gt; myfile.txt<br />
dir &gt;&gt; myfile.txt</p></blockquote>
<p><strong>Redirection for logging. </strong>This is a great way to make log files, which can even have the date and time with a simple improvement over that last example:</p>
<blockquote><p>echo %date%, %time%: Listing a directory. &gt; myfile.txt<br />
dir &gt;&gt; myfile.txt</p></blockquote>
<p>Using this technique, you can log not just what your batch scripts are trying to do, but what the results are. For instance, let's say we're generating a batch script that automatically creates accounts and drops them in a group. If I'm doing this in AD, I might have code like this:</p>
<blockquote><p># Add user "joe" to the "MyGroup" group.<br />
net group MyGroup joe /add</p></blockquote>
<p>To log the result of this, I might try:</p>
<blockquote><p>net group MyGroup joe /add &gt;&gt; AddAccts.log</p></blockquote>
<p><strong>Better error logging. </strong>When this command succeeds, it outputs, "This command completed successfully." It will output this to the log file, and you know the net group command succeeded. However, if there were errors, it will output, "The command completed with one or more errors." However, the standard output doesn't include the actual error messages, even though you can see them outputting to the screen. This is because there is a separate error stream, and by default, the redirection operator only streams the standard output.</p>
<p>This is where the <strong>&gt;&amp;</strong> operator comes in. This will pass the output from one "stream", or "handle" into another. This means you can take a command's error stream, and pass it into its output stream, so that both standard output and error output will be together.</p>
<p>Everything thus far was in Microsoft's documentation page I referred to earlier. But now how do you use the &gt;&amp; operator? I stumbled across Eric Jarvi's blog post, "<a target="_blank" href="http://blogs.msdn.com/ejarvi/archive/2005/01/28/362870.aspx">Redirecting stderr to stdout on the command line</a>", which has an example in the comments.</p>
<p>A quick preface: The standard output stream has a handle of 1, and the error stream has a handle of 2. That being said, take the above example, and modify it like this so that both stdout and stderr will stream to your file:</p>
<blockquote><p>net group MyGroup joe /add 1&gt;&gt;AddAccts.log 2&gt;&amp;1</p></blockquote>
<p>This code is effectively saying: "Perform the net group command, then output the stdout to AddAccts.log, but also redirect the stderr stream into the stdout stream at the same time."</p>
<p>As a result, you have stdout and stderr both in your file. Your log will now give you much more meaningful feedback on any errors your batch scripts might be encountering.</p>
<p><strong>What about combining stdout and stderr when piping?</strong> It may not be readily apparent, but you can also accomplish this with the 2&gt;&amp;1 redirection. It's just important where you place it; the redirection must occur before the pipe. So something like this would do the trick:</p>
<blockquote><p>mycmd 2&gt;&amp;1 | othercmd</p></blockquote>
<p>This would properly send both stdout and stderr from "mycmd" into the stdin stream for "othercmd".</p>
<p>I find the above operators the most commonly used in my development. I hope you found this information useful.</p>
<p><strong>What about sending <em>just</em> stderr?</strong> This is simple. Take a look at <a href="/redirecting-errors-to-a-file-in-windows-batch-scripts/">Redirecting Errors to a File in Windows Batch Scripts</a> for a quick post on doing that.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/redirecting-output-to-a-file-in-windows-batch-scripts/feed/</wfw:commentRss>
		<slash:comments>82</slash:comments>
		</item>
	</channel>
</rss>

