Wednesday, January 14, 2015

windows - Starting a batch file with spaces / quotation marks preventing the batch from running



I have this simple batch script. Lets call it 'Hello World.bat':



echo "Hello World!"



In a command line, running



cmd /c start "C:\path\to\Hello World.bat"


causes the a new command line window to show up, but the code in the .bat file is not executed.



I can rename this bat file to Hello_World.bat, remove the quotes from the command line command, and it works fine. However, with the quotes (which are necessary due to the spaces), it will not work.




Any suggestions? The application I'm working on calls customer-placed batch files, so unfortunately just renaming it isn't an option.


Answer



The Start command actually requires you to put in a title parameter like this:



start [""] [/d <path>]<br/></code></pre><br/><br/><p>You can get around this by adding an empty " " before the path to your file, like this:</p><br/><br/><br/><pre><code>cmd start "" /c "C:\path\to\Hello World.bat"<br/></code></pre><br/>    </div>
<div style='clear: both;'></div>
</div>
<div class='post-footer'>
<div class='post-footer-line post-footer-line-1'>
<span class='post-author vcard'>
</span>
<span class='post-timestamp'>
-
<meta content='https://stspru.blogspot.com/2015/01/windows-starting-batch-file-with-spaces.html' itemprop='url'/>
<a class='timestamp-link' href='https://stspru.blogspot.com/2015/01/windows-starting-batch-file-with-spaces.html?m=1' rel='bookmark' title='permanent link'><abbr class='published' itemprop='datePublished' title='2015-01-14T11:36:00-08:00'>January 14, 2015</abbr></a>
</span>
<span class='post-comment-link'>
</span>
</div>
<div class='post-footer-line post-footer-line-2'>
<div class='mobile-link-button goog-inline-block' id='mobile-share-button'>
<a href='javascript:void(0);'>Share</a>
</div>
</div>
</div>
</div>
<div class='comments' id='comments'>
<a name='comments'></a>
<h4>No comments:</h4>
<div id='Blog1_comments-block-wrapper'>
<dl class='avatar-comment-indent' id='comments-block'>
</dl>
</div>
<p class='comment-footer'>
<div class='comment-form'>
<a name='comment-form'></a>
<h4 id='comment-post-message'>
<a href='javascript:void(0)' id='Blog1_comment-editor-toggle-link'>Post a Comment</a></h4>
<p>
</p>
<a href='https://www.blogger.com/comment/frame/1095981230728817725?po=2602251960586516427&hl=en&saa=85391&origin=https://stspru.blogspot.com&m=1' id='comment-editor-src'></a>
<iframe allowtransparency='true' class='blogger-iframe-colorize blogger-comment-from-post' frameborder='0' height='410px' id='comment-editor' name='comment-editor' src='' style='display: none' width='100%'></iframe>
<script src='https://www.blogger.com/static/v1/jsbin/1345082660-comment_from_post_iframe.js' type='text/javascript'></script>
<script type='text/javascript'>
      BLOG_CMT_createIframe('https://www.blogger.com/rpc_relay.html');
    </script>
</div>
</p>
</div>
</div>
</div>
</div>
</div>
<div class='blog-pager' id='blog-pager'>
<div class='mobile-link-button' id='blog-pager-newer-link'>
<a class='blog-pager-newer-link' href='https://stspru.blogspot.com/2015/01/linux-how-to-ssh-to-ec2-instance-in-vpc.html?m=1' id='Blog1_blog-pager-newer-link' title='Newer Post'>‹</a>
</div>
<div class='mobile-link-button' id='blog-pager-older-link'>
<a class='blog-pager-older-link' href='https://stspru.blogspot.com/2015/01/command-line-http-server-for-windows.html?m=1' id='Blog1_blog-pager-older-link' title='Older Post'>›</a>
</div>
<div class='mobile-link-button' id='blog-pager-home-link'>
<a class='home-link' href='https://stspru.blogspot.com/?m=1'>Home</a>
</div>
<div class='mobile-desktop-link'>
<a class='home-link' href='https://stspru.blogspot.com/2015/01/windows-starting-batch-file-with-spaces.html?m=0'>View web version</a>
</div>
</div>
<div class='clear'></div>
</div>
</div>
</div>
</div>
<div class='column-left-outer'>
<div class='column-left-inner'>
<aside>
</aside>
</div>
</div>
<div class='column-right-outer'>
<div class='column-right-inner'>
<aside>
</aside>
</div>
</div>
</div>
<div style='clear: both'></div>
<!-- columns -->
</div>
<!-- main -->
</div>
</div>
<div class='main-cap-bottom cap-bottom'>
<div class='cap-left'></div>
<div class='cap-right'></div>
</div>
</div>
<footer>
<div class='footer-outer'>
<div class='footer-cap-top cap-top'>
<div class='cap-left'></div>
<div class='cap-right'></div>
</div>
<div class='fauxborder-left footer-fauxborder-left'>
<div class='fauxborder-right footer-fauxborder-right'></div>
<div class='region-inner footer-inner'>
<div class='foot section' id='footer-1'>
</div>
<!-- outside of the include in order to lock Attribution widget -->
<div class='foot section' id='footer-3' name='Footer'><div class='widget Attribution' data-version='1' id='Attribution1'>
<div class='widget-content' style='text-align: center;'>
Powered by <a href='https://www.blogger.com' target='_blank'>Blogger</a>.
</div>
<div class='clear'></div>
</div></div>
</div>
</div>
<div class='footer-cap-bottom cap-bottom'>
<div class='cap-left'></div>
<div class='cap-right'></div>
</div>
</div>
</footer>
<!-- content -->
</div>
</div>
<div class='content-cap-bottom cap-bottom'>
<div class='cap-left'></div>
<div class='cap-right'></div>
</div>
</div>
</div>
<script type='text/javascript'>
    window.setTimeout(function() {
        document.body.className = document.body.className.replace('loading', '');
      }, 10);
  </script>

<script type="text/javascript" src="https://www.blogger.com/static/v1/widgets/382300504-widgets.js"></script>
<script type='text/javascript'>
var BLOG_BASE_IMAGE_URL = 'https://resources.blogblog.com/img';var BLOG_LANG_DIR = 'ltr';window['__wavt'] = 'AOuZoY5qhw4Rl0HRIUS9hM_ukBQJJUUSXQ:1767001906968';_WidgetManager._Init('//www.blogger.com/rearrange?blogID\x3d1095981230728817725','//stspru.blogspot.com/2015/01/windows-starting-batch-file-with-spaces.html?m\x3d1','1095981230728817725');
_WidgetManager._SetDataContext([{'name': 'blog', 'data': {'blogId': '1095981230728817725', 'title': 'Blog', 'url': 'https://stspru.blogspot.com/2015/01/windows-starting-batch-file-with-spaces.html?m\x3d1', 'canonicalUrl': 'https://stspru.blogspot.com/2015/01/windows-starting-batch-file-with-spaces.html', 'homepageUrl': 'https://stspru.blogspot.com/?m\x3d1', 'searchUrl': 'https://stspru.blogspot.com/search', 'canonicalHomepageUrl': 'https://stspru.blogspot.com/', 'blogspotFaviconUrl': 'https://stspru.blogspot.com/favicon.ico', 'bloggerUrl': 'https://www.blogger.com', 'hasCustomDomain': false, 'httpsEnabled': true, 'enabledCommentProfileImages': true, 'gPlusViewType': 'FILTERED_POSTMOD', 'adultContent': false, 'analyticsAccountNumber': '', 'encoding': 'UTF-8', 'locale': 'en', 'localeUnderscoreDelimited': 'en', 'languageDirection': 'ltr', 'isPrivate': false, 'isMobile': true, 'isMobileRequest': true, 'mobileClass': ' mobile', 'isPrivateBlog': false, 'isDynamicViewsAvailable': true, 'feedLinks': '\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22Blog - Atom\x22 href\x3d\x22https://stspru.blogspot.com/feeds/posts/default\x22 /\x3e\n\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/rss+xml\x22 title\x3d\x22Blog - RSS\x22 href\x3d\x22https://stspru.blogspot.com/feeds/posts/default?alt\x3drss\x22 /\x3e\n\x3clink rel\x3d\x22service.post\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22Blog - Atom\x22 href\x3d\x22https://www.blogger.com/feeds/1095981230728817725/posts/default\x22 /\x3e\n\n\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22Blog - Atom\x22 href\x3d\x22https://stspru.blogspot.com/feeds/2602251960586516427/comments/default\x22 /\x3e\n', 'meTag': '', 'adsenseHostId': 'ca-host-pub-1556223355139109', 'adsenseHasAds': true, 'adsenseAutoAds': false, 'boqCommentIframeForm': true, 'loginRedirectParam': '', 'view': '', 'dynamicViewsCommentsSrc': '//www.blogblog.com/dynamicviews/4224c15c4e7c9321/js/comments.js', 'dynamicViewsScriptSrc': '//www.blogblog.com/dynamicviews/daef15016aa26cab', 'plusOneApiSrc': 'https://apis.google.com/js/platform.js', 'disableGComments': true, 'interstitialAccepted': false, 'sharing': {'platforms': [{'name': 'Get link', 'key': 'link', 'shareMessage': 'Get link', 'target': ''}, {'name': 'Facebook', 'key': 'facebook', 'shareMessage': 'Share to Facebook', 'target': 'facebook'}, {'name': 'BlogThis!', 'key': 'blogThis', 'shareMessage': 'BlogThis!', 'target': 'blog'}, {'name': 'X', 'key': 'twitter', 'shareMessage': 'Share to X', 'target': 'twitter'}, {'name': 'Pinterest', 'key': 'pinterest', 'shareMessage': 'Share to Pinterest', 'target': 'pinterest'}, {'name': 'Email', 'key': 'email', 'shareMessage': 'Email', 'target': 'email'}], 'disableGooglePlus': true, 'googlePlusShareButtonWidth': 0, 'googlePlusBootstrap': '\x3cscript type\x3d\x22text/javascript\x22\x3ewindow.___gcfg \x3d {\x27lang\x27: \x27en\x27};\x3c/script\x3e'}, 'hasCustomJumpLinkMessage': false, 'jumpLinkMessage': 'Read more', 'pageType': 'item', 'postId': '2602251960586516427', 'pageName': 'windows - Starting a batch file with spaces / quotation marks\npreventing the batch from running', 'pageTitle': 'Blog: windows - Starting a batch file with spaces / quotation marks\npreventing the batch from running'}}, {'name': 'features', 'data': {}}, {'name': 'messages', 'data': {'edit': 'Edit', 'linkCopiedToClipboard': 'Link copied to clipboard!', 'ok': 'Ok', 'postLink': 'Post Link'}}, {'name': 'template', 'data': {'name': 'custom', 'localizedName': 'Custom', 'isResponsive': false, 'isAlternateRendering': true, 'isCustom': true}}, {'name': 'view', 'data': {'classic': {'name': 'classic', 'url': '?view\x3dclassic'}, 'flipcard': {'name': 'flipcard', 'url': '?view\x3dflipcard'}, 'magazine': {'name': 'magazine', 'url': '?view\x3dmagazine'}, 'mosaic': {'name': 'mosaic', 'url': '?view\x3dmosaic'}, 'sidebar': {'name': 'sidebar', 'url': '?view\x3dsidebar'}, 'snapshot': {'name': 'snapshot', 'url': '?view\x3dsnapshot'}, 'timeslide': {'name': 'timeslide', 'url': '?view\x3dtimeslide'}, 'isMobile': true, 'title': 'windows - Starting a batch file with spaces / quotation marks\npreventing the batch from running', 'description': 'I have this simple batch script. Lets call it \x27Hello World.bat\x27: echo \x22Hello World!\x22 In a command line, running cmd /c start \x22C:\\path\\to\\Hel...', 'url': 'https://stspru.blogspot.com/2015/01/windows-starting-batch-file-with-spaces.html?m\x3d1', 'type': 'item', 'isSingleItem': true, 'isMultipleItems': false, 'isError': false, 'isPage': false, 'isPost': true, 'isHomepage': false, 'isArchive': false, 'isLabelSearch': false, 'postId': 2602251960586516427}}]);
_WidgetManager._RegisterWidget('_HeaderView', new _WidgetInfo('Header1', 'header', document.getElementById('Header1'), {}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_BlogView', new _WidgetInfo('Blog1', 'main', document.getElementById('Blog1'), {'cmtInteractionsEnabled': false, 'mobile': true}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_FeaturedPostView', new _WidgetInfo('FeaturedPost1', 'main', document.getElementById('FeaturedPost1'), {}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_PopularPostsView', new _WidgetInfo('PopularPosts1', 'main', document.getElementById('PopularPosts1'), {}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_BlogSearchView', new _WidgetInfo('BlogSearch1', 'sidebar-right-1', document.getElementById('BlogSearch1'), {}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_BlogArchiveView', new _WidgetInfo('BlogArchive1', 'sidebar-right-1', document.getElementById('BlogArchive1'), {'languageDirection': 'ltr', 'loadingMessage': 'Loading\x26hellip;'}, 'displayModeFull'));
_WidgetManager._RegisterWidget('_AttributionView', new _WidgetInfo('Attribution1', 'footer-3', document.getElementById('Attribution1'), {}, 'displayModeFull'));
</script>
</body>
</html>