<?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>bat sleep &#8211; スグブログ</title>
	<atom:link href="https://sugublog.org/tag/bat-sleep/feed/" rel="self" type="application/rss+xml" />
	<link>https://sugublog.org</link>
	<description>ブログ運営について発信中</description>
	<lastBuildDate>Fri, 23 Feb 2024 02:52:07 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://sugublog.org/wp-content/uploads/2021/07/icon_20210703-min-150x150.png</url>
	<title>bat sleep &#8211; スグブログ</title>
	<link>https://sugublog.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【bat】バッチでsleepコマンドを使用して数秒待つ！失敗する人必見</title>
		<link>https://sugublog.org/bat-sleep/</link>
					<comments>https://sugublog.org/bat-sleep/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[suguru]]></dc:creator>
		<pubDate>Fri, 23 Feb 2024 02:52:06 +0000</pubDate>
				<category><![CDATA[bat]]></category>
		<category><![CDATA[bat sleep]]></category>
		<guid isPermaLink="false">https://sugublog.org/?p=6377</guid>

					<description><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2022/01/vitamins_0117-3-1024x683.jpg" class="webfeedsFeaturedVisual" /></p>batでsleepコマンドを使用して、ミリ秒単位で処理を止めたい時もあると思います。 今回はsleepコマンドを使用して、batの処理を数秒止めて再開させたいと思います。 またsleepコマンドを使用しても想定通りの動き [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2022/01/vitamins_0117-3-1024x683.jpg" class="webfeedsFeaturedVisual" /></p>
<p><strong><span class="swl-inline-color has-swl-deep-01-color">bat</span></strong>で<strong><span class="swl-inline-color has-swl-deep-01-color">sleep</span></strong>コマンドを使用して、<strong>ミリ秒単位で処理を止めたい</strong>時もあると思います。</p>



<p>今回はsleepコマンドを使用して、batの処理を数秒止めて再開させたいと思います。</p>



<p>また<span class="swl-marker mark_yellow">sleepコマンドを使用しても想定通りの動きをしない場合の対処法</span>も教えます。</p>


<div class="p-blogParts post_content" data-partsID="5030">
<p>windowsのプロンプトで使用できるbatやpythonやphpを使用して、業務効率化やWebサイトを作成しております。javaやシェルスクリプトなど、様々なプログラミングを行った実績ありの筆者です。</p>
</div>


<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle ads" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-9330904718533231" data-ad-slot="6086594686"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">bat(バッチ)でsleepコマンドのやり方</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="576" src="https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-3-1024x576.jpg" alt="batを教えます" class="wp-image-4580" srcset="https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-3-1024x576.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-3-300x169.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-3-768x432.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-3.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p><span class="swl-marker mark_orange"><strong><span class="swl-inline-color has-swl-deep-01-color">bat</span></strong>での<strong><span class="swl-inline-color has-swl-deep-01-color">sleep</span></strong>コマンドは処理を<strong>決めた秒数だけ一時停止</strong>する効果があります。</span></p>



<p>基礎構文を下に教示します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sleep 秒数</code></pre></div>



<p>これを入れるだけでbat処理を秒数だけ一時停止する事が可能です。</p>



<h2 class="wp-block-heading">bat(バッチ)のsleepコマンドと同じ動きをするコマンド</h2>



<p class="is-style-big_icon_caution">しかしsleepコマンドはwindowsの環境などで動かない場合が存在します。</p>



<p>そういった場合には「timeout」コマンドを使用すれば同じ効果が得られます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>timeout /t 秒数</code></pre></div>



<p>timeoutコマンドのその他のオプションなどは以下の記事でまとめています。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/10/カスタマイズ1013-1-300x200.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-base-timeout/">【bat基礎】Timeoutの使い方！効かない時の対処法などご紹介</a>
						<span class="p-blogCard__excerpt">時間指定して経過後、続きからbatファイルを動かしたい場合は「Timeout」コマンドを使用します。 batファイルで一時停止させたい場合「Pause」コマンドを使用しますが、&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h2 class="wp-block-heading">bat(バッチ)でsleepコマンドが動かない時の対処法</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="683" src="https://sugublog.org/wp-content/uploads/2021/11/programing_1122-7-1024x683.jpg" alt="エラー対処法" class="wp-image-4564" srcset="https://sugublog.org/wp-content/uploads/2021/11/programing_1122-7-1024x683.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/programing_1122-7-300x200.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/programing_1122-7-768x512.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/programing_1122-7.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="is-style-big_icon_caution">しかしsleepコマンドもtimeoutコマンドもwindowsの環境などで動かない場合が存在します。</p>



<p>そんな時の対処法を教えます。</p>



<p>「powershell sleep」コマンドを使用すれば可能です。</p>



<p class="is-style-icon_book">powershellとはwindowsのbatの拡張版のようなものです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>powershell sleep 秒数</code></pre></div>



<p>これなら確実に動きますので、「powershell sleep」のコマンドを推奨します。</p>



<h2 class="wp-block-heading">bat(バッチ)のsleepでミリ秒を指定する方法</h2>



<p><span class="swl-marker mark_orange"><strong><span class="swl-inline-color has-swl-deep-01-color">bat</span></strong>の<strong><span class="swl-inline-color has-swl-deep-01-color">sleep</span></strong>で<strong>ミリ秒を指定</strong>したい時</span>もあると思います。</p>



<p>そんな時は以下の様に記述してください。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>powershell sleep 0.001</code></pre></div>



<p>これでミリ秒単位でbat処理を一時停止する事が可能です。</p>



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9330904718533231"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-9330904718533231"
     data-ad-slot="8455594968"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>




<h2 class="wp-block-heading">実践：batのsleepで処理を止める</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="683" src="https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1-1024x683.jpg" alt="training" class="wp-image-4541" srcset="https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1-1024x683.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1-300x200.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1-768x512.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-1.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p>では実際にbatのsleepを使用してみます。</p>



<h3 class="wp-block-heading">sleepを使用したbatファイル説明</h3>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>@echo off

echo ①この行が最初の行です!
powershell sleep 5
echo ②この行が最後の行です！

pause</code></pre></div>



<p class="is-style-icon_pen">「@echo off」はbatファイルの1行目に記述するおまじないだと思ってください。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/12/PC教室20211216-8-300x229.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-echo-off/">【bat基礎】バッチで「@echo off」の意味や効果とは？</a>
						<span class="p-blogCard__excerpt">batファイルの初めに「@echo off」という記載があると思いますが、この意味は何でしょうか？ なんの効果があるのでしょうか？「@echo off」が無ければどうなるのでしょ&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p>最初の文字列を表示してから<span class="swl-marker mark_orange">「powershell speep」コマンドで5秒待ってから最終行の文字列を表示します。</span></p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/07/html-007-2-300x225.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-base-echo/">【bat基礎】バッチファイルのechoで文字列表示する！エラー対処法あり</a>
						<span class="p-blogCard__excerpt">batファイルで「echo」の使い方を今回は行います。 「echo」コマンドは指定の文字列を標準出力に表示する事が出来るコマンドです。 ただ文字列を表示するだけでなく、フ&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p class="is-style-icon_pen">最後のpauseコマンドはechoなどを使用した時に、確認が便利になるコマンドです。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/09/jump0907-3-300x225.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-base-pause/">【bat基礎】バッチでPAUSEを使用して一時停止する！waitはありません</a>
						<span class="p-blogCard__excerpt">バッチファイルを使用していて、途中で止めたいところで一時停止したい場合ないでしょうか？ そんな時バッチファイルでは「PAUSE」を使用します。 PAUSEの実用例を現役&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h3 class="wp-block-heading">sleepを使用したbatファイルを実行した結果</h3>



<p>ではこのbatファイルを実行してみます。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/07/analytics-2-300x157.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-execution/">【bat】バッチを実行する方法！実行できない時の対処法などをご紹介</a>
						<span class="p-blogCard__excerpt">batファイルが既にありそれを実行してと言われたけど、どうやって実行すればわからない人の悩みに答えます。 またbatを実行しようとしたけど、できなかった時の原因と対&#8230;</span>					</div>
				</div>
			</div>
		</div>


<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>①この行が最初の行です!</code></pre></div>



<p>最初の文字列が表示されます。</p>



<p>5秒間待ちが発生します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>①この行が最初の行です!
②この行が最後の行です！
続行するには何かキーを押してください . . .</code></pre></div>



<p>5秒後に最後の文字列が表示されました。</p>



<h2 class="wp-block-heading">まとめ：bat(バッチ)でsleepコマンドのやり方</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="683" src="https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-1-1024x683.jpg" alt="batを教えます" class="wp-image-4578" srcset="https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-1-1024x683.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-1-300x200.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-1-768x512.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/programing_school1123-1.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p><span class="swl-marker mark_orange"><strong><span class="swl-inline-color has-swl-deep-01-color">bat</span></strong>で<strong><span class="swl-inline-color has-swl-deep-01-color">sleep</span></strong>を使用すれば<strong>処理を指定した時間だけ止める</strong>事ができる。</span></p>



<p>sleepのコマンドは以下です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>sleep 秒数</code></pre></div>



<p>その他のコマンドで<span class="swl-bg-color has-swl-deep-02-background-color">sleepと同じ効果のあるコマンド</span>はtimeoutで構文は以下です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>timeout /t 秒数</code></pre></div>



<p>環境によっては<span class="swl-marker mark_yellow">sleepもtimeoutも動かない時があるので</span>、powershellコマンドを使用するのが推奨です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>powershell sleep 秒数</code></pre></div>



<p>秒数の箇所はミリ秒単位でも指定可能。1ミリ秒を指定する時のやり方です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>powershell sleep 0.001</code></pre></div>
]]></content:encoded>
					
					<wfw:commentRss>https://sugublog.org/bat-sleep/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
