<?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>Mark Needham &#187; Batch Scripting</title>
	<atom:link href="http://www.markhneedham.com/blog/category/batch-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Sat, 31 Jul 2010 07:06:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Getting latest tagged revision in SVN from DOS/Batch script</title>
		<link>http://www.markhneedham.com/blog/2008/08/16/getting-latest-tagged-revision-in-svn-from-dosbatch-script/</link>
		<comments>http://www.markhneedham.com/blog/2008/08/16/getting-latest-tagged-revision-in-svn-from-dosbatch-script/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 23:10:51 +0000</pubDate>
		<dc:creator>Mark Needham</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Version Control]]></category>
		<category><![CDATA[batch-scripts]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[dos]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=127</guid>
		<description><![CDATA[The way we have setup the build on our continuous integration server, Team City is configured to create a new tag every time the functional tests past successful on that machine. We then have a QA and Showcase build that we can run to deploy all the artifacts necessary to launch the application on that [...]]]></description>
			<content:encoded><![CDATA[<p>The way we have setup the build on our continuous integration server, <a href="http://www.jetbrains.com/teamcity/">Team City</a> is configured to create a new tag every time the functional tests past successful on that machine.</p>
<p>We then have a QA and Showcase build that we can run to deploy all the artifacts necessary to launch the application on that machine.</p>
<p>Originally I had just written the batch script to take in the tag of the build which the user could find by looking through <a href="http://tortoisesvn.tigris.org/">repo-browser</a> for the last tag created. This quickly became very tedious so I started looking for a way to get the latest tagged revision from the command line.</p>
<p>We thought it would be possible to get this information using svn info but it turned out that the information returned by svn info about revisions doesn't necessarily refer  to the latest created tag. We ended up using svn log and then parsing through that data. It's a bit messy but it does the job (I name each tagged version of the code as 'build-{TeamCity-Build-Number}):</p>
<table class="CodeRay" border="0">
<tbody>
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">FOR /F "Tokens=2" %%i in ('svn log /tags/path --limit=1 -v ^| find "build"') do set TMP=%%i<tt>
</tt>FOR /F "Tokens=2 delims=/" %%i in ('echo %TMP%') do SET TAG=%%i</pre>
</td>
</tr>
</tbody>
</table>
<p>The for loop uses a space as its default delimiter so that's what the 'delims=/' is doing on the second line, the 'Tokens=2&#8242; allows us to get the second token after the string is split and the '^' in the first command is being used to escape the pipe.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markhneedham.com/blog/2008/08/16/getting-latest-tagged-revision-in-svn-from-dosbatch-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Auto complete with tab in DOS</title>
		<link>http://www.markhneedham.com/blog/2008/08/13/auto-completion-with-tab-in-dos/</link>
		<comments>http://www.markhneedham.com/blog/2008/08/13/auto-completion-with-tab-in-dos/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 22:55:38 +0000</pubDate>
		<dc:creator>Mark Needham</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[auto-completion]]></category>
		<category><![CDATA[dos]]></category>
		<category><![CDATA[windows-command-prompt]]></category>

		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=105</guid>
		<description><![CDATA[It's becoming quite a couple of weeks of learning for me around DOS and I have another tip that I just learnt today. I always found it really frustrating when using the windows command prompt that I couldn't get Unix style tab auto completion. To navigate my way to a directory I would do the [...]]]></description>
			<content:encoded><![CDATA[<p>It's becoming quite a couple of weeks of learning for me around DOS and I have another tip that I just learnt today.</p>
<p>I always found it really frustrating when using the windows command prompt that I couldn't get Unix style tab auto completion. To navigate my way to a directory I would do the following:</p>
<table class="CodeRay" border="0">
<tbody>
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">C:\&gt;cd Downloads<tt>
</tt><tt>
</tt>C:\Downloads&gt;cd nant-0.85<tt>
</tt><tt>
</tt>C:\Downloads\nant-0.85&gt;cd bin<tt>
</tt><tt>
</tt>C:\Downloads\nant-0.85\bin&gt;</pre>
</td>
</tr>
</tbody>
</table>
<p>It is very tedious as you might imagine. I would try placing a forward slash after each directory in the hope that it would allow me to scroll through the next directory down but to no avail.</p>
<p>Little did I know that in fact I needed to be using the backslash. The above can now be done in one line using Unix style tabbing auto completion:</p>
<table class="CodeRay" border="0">
<tbody>
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">C:\&gt;cd Downloads\nant-0.85\bin<tt>
</tt><tt>
</tt>C:\Downloads\nant-0.85\bin&gt;</pre>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.markhneedham.com/blog/2008/08/13/auto-completion-with-tab-in-dos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>If Else statements in batch files</title>
		<link>http://www.markhneedham.com/blog/2008/08/13/if-else-statements-in-batch-files/</link>
		<comments>http://www.markhneedham.com/blog/2008/08/13/if-else-statements-in-batch-files/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 21:27:40 +0000</pubDate>
		<dc:creator>Mark Needham</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[batch-scripts]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[dos]]></category>

		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=98</guid>
		<description><![CDATA[I mentioned in a couple of earlier posts that I've been doing quite a bit of work with batch files and the windows command line, and today I wanted to do an If Else statement in one of my scripts. I thought it would be relatively simple, but after various searches and having read articles [...]]]></description>
			<content:encoded><![CDATA[<p>I mentioned in a couple of <a href="http://www.markhneedham.com/blog/2008/08/12/getting-the-current-working-directory-from-dos-or-batch-file/">earlier</a> <a href="http://www.markhneedham.com/blog/2008/08/08/spaces-in-batch-scripts/">posts</a> that I've been doing quite a bit of work with batch files and the windows command line, and today I wanted to do an If Else statement in one of my scripts.</p>
<p>I thought it would be relatively simple, but after various searches and having read articles that suggested that there wasn't an ELSE construct in batch land I finally found a <a href="http://www.codeguru.com/forum/showthread.php?t=377124">forum post</a> which explained how to do it.</p>
<p>The script I'm working on takes in a working directory as one of the arguments and what I wanted to do was either set a variable to be the value passed in, or if the value passed in was '.' then to set it to the <a href="2008/08/12/getting-the-current-working-directory-from-dos-or-batch-file/">current working directory</a>.</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">IF &quot;%1&quot;==&quot;.&quot;  (<tt>
</tt>  set WORKING_DIRECTORY=%cd%<tt>
</tt>) ELSE (<tt>
</tt>  set WORKING_DIRECTORY=%1<tt>
</tt>)</pre>
</td>
</tr>
</table>
<p>I played around with this a little bit and it does seem that the brackets need to be in that exact format otherwise it doesn't work at all. Even putting brackets around the IF part of the statement will stop the script from working as expected. </p>
<p>IF statements on their own are much easier to deal with. To check for an empty argument for example either of the following will work:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">IF &quot;%1&quot;==&quot;&quot; GOTO usage<tt>
</tt><tt>
</tt>IF [%1]==[] GOTO usage</pre>
</td>
</tr>
</table>
<p>It does all seem a bit fiddly and <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx">Powershell</a> is probably the way forwards, but for now batch scripts it is!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markhneedham.com/blog/2008/08/13/if-else-statements-in-batch-files/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Getting the current working directory from DOS or Batch file</title>
		<link>http://www.markhneedham.com/blog/2008/08/12/getting-the-current-working-directory-from-dos-or-batch-file/</link>
		<comments>http://www.markhneedham.com/blog/2008/08/12/getting-the-current-working-directory-from-dos-or-batch-file/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 21:37:27 +0000</pubDate>
		<dc:creator>Mark Needham</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[batch-scripts]]></category>
		<category><![CDATA[dos]]></category>

		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=87</guid>
		<description><![CDATA[In the world of batch files I've been trying for ages to work out how to get the current/present working directory to make the batch script I'm working on a bit more flexible. In Unix it's easy, just call 'pwd' and you have it. I wasn't expecting something that simple in Windows but it is! [...]]]></description>
			<content:encoded><![CDATA[<p>In the world of batch files I've been trying for ages to work out how to get the current/present working directory to make the batch script I'm working on a bit more flexible.</p>
<p>In Unix it's easy, just call 'pwd' and you have it. I wasn't expecting something that simple in Windows but it is! A call to 'cd' is all that's needed. If you need to set it in a batch script the following line does the trick:</p>
<table class="CodeRay" border="0">
<tbody>
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">set WORKING_DIRECTORY=%cd%</pre>
</td>
</tr>
</tbody>
</table>
<p>I was surprised that something so simple (I do now feel like an idiot) wasn't easier to find on Google. I ended up going via Experts Exchange (how they end up with such high search results when you have to pay to see the information is beyond me) and several other <a href="http://www.codeguru.com/forum/archive/index.php/t-96124.html">verbose ways</a> of solving the problem before finally coming across <a href="http://blogs.msdn.com/oldnewthing/archive/2005/01/28/362565.aspx">this article</a> which explained it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markhneedham.com/blog/2008/08/12/getting-the-current-working-directory-from-dos-or-batch-file/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
