<?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 実行 &#8211; スグブログ</title>
	<atom:link href="https://sugublog.org/tag/bat-%E5%AE%9F%E8%A1%8C/feed/" rel="self" type="application/rss+xml" />
	<link>https://sugublog.org</link>
	<description>ブログ運営について発信中</description>
	<lastBuildDate>Sun, 18 Feb 2024 10:05:47 +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 実行 &#8211; スグブログ</title>
	<link>https://sugublog.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【bat】バッチを実行する方法！実行できない時の対処法などをご紹介</title>
		<link>https://sugublog.org/bat-execution/</link>
					<comments>https://sugublog.org/bat-execution/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[suguru]]></dc:creator>
		<pubDate>Sun, 18 Feb 2024 10:05:45 +0000</pubDate>
				<category><![CDATA[bat]]></category>
		<category><![CDATA[bat 実行]]></category>
		<guid isPermaLink="false">https://sugublog.org/?p=6295</guid>

					<description><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/07/analytics-2-1024x534.jpg" class="webfeedsFeaturedVisual" /></p>batファイルが既にありそれを実行してと言われたけど、どうやって実行すればわからない人の悩みに答えます。 またbatを実行しようとしたけど、できなかった時の原因と対処法も知っておいた方が良いです。 筆者も現役のエンジニア [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/07/analytics-2-1024x534.jpg" class="webfeedsFeaturedVisual" /></p>
<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">実行</span></strong>してと言われたけど、<strong>どうやって実行すればわからない</strong>人</span>の悩みに答えます。</p>



<p>また<span class="swl-marker mark_yellow"><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">できなかった時の原因と対処法</span></strong></span>も知っておいた方が良いです。</p>



<p>筆者も現役のエンジニアで、バッチファイルを実行できない時もありましたのでここに記述しておきます。</p>


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


<p class="has-border -border02">この記事を読めばbatファイルを実行できない。なんて事はなくなります。</p>



<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ファイルを実行する方法</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="560" src="https://sugublog.org/wp-content/uploads/2021/11/programing_1122-4-1024x560.jpg" alt="batファイルを実行" class="wp-image-4561" srcset="https://sugublog.org/wp-content/uploads/2021/11/programing_1122-4-1024x560.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/programing_1122-4-300x164.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/programing_1122-4-768x420.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/programing_1122-4.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p><strong><span class="swl-inline-color has-swl-deep-01-color"><span class="swl-fz u-fz-l">batファイルを実行する方法</span></span></strong>は基本的に２つ覚えておけば良いでしょう！</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl"><div class="cap_box_ttl"><span>batファイルを実行する方法</span></div><div class="cap_box_content">
<ul class="wp-block-list">
<li>batファイルをダブルクリックかエンターでそのまま実行する</li>



<li>batファイルのパスをエクスプローラーに入れて実行する</li>
</ul>
</div></div>



<h3 class="wp-block-heading">batファイルをダブルクリックかエンターでそのまま実行する</h3>



<p>batファイルがあるフォルダがわかっていれば、<strong><span class="swl-inline-color has-swl-deep-01-color"><span class="swl-fz u-fz-l">batファイル自体をダブルクリックかエンターで実行</span></span></strong>できます。</p>



<p><strong>管理者権限で実行したい場合</strong>は、batファイルを右クリックして<strong>「管理者として実行」をクリック</strong>します。</p>


<div class="wp-block-image is-style-border">
<figure class="aligncenter size-full"><img decoding="async" width="700" height="189" src="https://sugublog.org/wp-content/uploads/2024/02/bat実行基本_管理者として実行1.png" alt="batを管理者として実行する" class="wp-image-6306" srcset="https://sugublog.org/wp-content/uploads/2024/02/bat実行基本_管理者として実行1.png 700w, https://sugublog.org/wp-content/uploads/2024/02/bat実行基本_管理者として実行1-300x81.png 300w" sizes="(max-width: 700px) 100vw, 700px" /></figure>
</div>


<p>ユーザーアカウントの制御のポップアップが表示されますので「はい」を選択してOKです。</p>


<div class="wp-block-image is-style-border">
<figure class="aligncenter size-full"><img decoding="async" width="446" height="362" src="https://sugublog.org/wp-content/uploads/2024/02/bat実行基本_管理者として実行2.png" alt="batを管理者として実行する" class="wp-image-6307" srcset="https://sugublog.org/wp-content/uploads/2024/02/bat実行基本_管理者として実行2.png 446w, https://sugublog.org/wp-content/uploads/2024/02/bat実行基本_管理者として実行2-300x243.png 300w" sizes="(max-width: 446px) 100vw, 446px" /></figure>
</div>


<h3 class="wp-block-heading">batファイルのパスをエクスプローラーに入れて実行する</h3>



<p>batファイルのパスがわかっている場合は、そのパスをエクスプローラーのパスにコピーしてエンターします。</p>


<div class="wp-block-image is-style-border">
<figure class="aligncenter size-full"><img decoding="async" width="616" height="171" src="https://sugublog.org/wp-content/uploads/2024/02/bat実行基本_パスを入れて実行.png" alt="batを実行する" class="wp-image-6305" srcset="https://sugublog.org/wp-content/uploads/2024/02/bat実行基本_パスを入れて実行.png 616w, https://sugublog.org/wp-content/uploads/2024/02/bat実行基本_パスを入れて実行-300x83.png 300w" sizes="(max-width: 616px) 100vw, 616px" /></figure>
</div>


<h2 class="wp-block-heading">batファイルが実行できない時の原因と対処法</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/06/shutterstock_1433996435-min-1024x683.jpg" alt="エラー" class="wp-image-2885"/></figure>
</div>


<p>batファイルを実行しても何もおきなかった場合の原因についてお話します。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl"><div class="cap_box_ttl"><span>batで実行してもなにもおきない時の動き</span></div><div class="cap_box_content">
<ul class="wp-block-list">
<li>実はbatが実行されている場合</li>



<li>本当にbatが実行されていない場合</li>
</ul>
</div></div>



<h3 class="wp-block-heading">実はbatが実行されている場合</h3>



<p><strong><span class="swl-bg-color has-swl-deep-01-background-color">実はbatが実行されている場合</span></strong>があります。以下のbatファイルを実行して見て下さい。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="batを実行出来ているが内容が見れないファイル"><code>@echo off
echo test</code></pre></div>


<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>

<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>実行結果は何もおきないとおもいます。</p>



<p>しかし実はbatは実行されています。実行実績としては以下です。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl"><div class="cap_box_ttl"><span>batが実行されるフロー</span></div><div class="cap_box_content">
<ol class="wp-block-list">
<li>コマンドプロンプトが立ち上がる</li>



<li>testと表示される</li>



<li>プロンプトが閉じる</li>
</ol>
</div></div>



<p>上のフローが一瞬で実行されているため、見えないだけです。</p>


<div class="swell-block-balloon"><div class="c-balloon -bln-left" data-col="red"><div class="c-balloon__icon -square"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://sugublog.org/wp-content/uploads/2021/02/cropped-dog003-150x150.png" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/02/cropped-dog003-150x150.png" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">batで悩んでいるワンコ</span></div><div class="c-balloon__body -thinking -border-on"><div class="c-balloon__text">
<p>原因はわかりました。見えるようにしたいです。</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>

<div class="swell-block-balloon"><div class="c-balloon -bln-right" data-col="green"><div class="c-balloon__icon -square"><img decoding="async" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="https://sugublog.org/wp-content/uploads/2021/02/mine_white_001.png" alt="" class="lazyload c-balloon__iconImg" width="80px" height="80px"><noscript><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/02/mine_white_001.png" alt="" class="c-balloon__iconImg" width="80px" height="80px"></noscript><span class="c-balloon__iconName">管理人</span></div><div class="c-balloon__body -speaking -border-on"><div class="c-balloon__text">
<p>では先程のbatの最後に「pause」を入れてみましょう！</p>
<span class="c-balloon__shapes"><span class="c-balloon__before"></span><span class="c-balloon__after"></span></span></div></div></div></div>


<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="batを実行出来ていてかつ内容が見れるファイル"><code>@echo off
echo test
pause</code></pre></div>



<p class="is-style-icon_pen">pauseは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/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>


<p>上のbatを実行した結果です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>test
続行するには何かキーを押してください . . .</code></pre></div>



<p>上手く表示されました。</p>



<p class="has-border -border02">このようにプロンプト上で実行結果を確認する場合はpauseコマンドを入れましょう！</p>



<h3 class="wp-block-heading">本当にbatが実行されていない場合</h3>



<p>サーバーの共有フォルダにbatを入れている環境もあるでしょう。</p>



<p>windows serverに共有フォルダ「共有１」があり、その配下に「echo_test」フォルダと「def.bat」があります。</p>


<div class="wp-block-image is-style-border">
<figure class="aligncenter size-full"><img decoding="async" width="683" height="299" src="https://sugublog.org/wp-content/uploads/2024/02/bat実行2_server_bat_def.bat_.png" alt="batを実行する" class="wp-image-6301" srcset="https://sugublog.org/wp-content/uploads/2024/02/bat実行2_server_bat_def.bat_.png 683w, https://sugublog.org/wp-content/uploads/2024/02/bat実行2_server_bat_def.bat_-300x131.png 300w" sizes="(max-width: 683px) 100vw, 683px" /></figure>
</div>


<p>「def.bat」の内容は以下です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="def.bat"><code>@echo off
set name=windows server2016</code></pre></div>



<p>変数「name」に「windows server2016」の文字列を入れています。</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/08/script_0809-11-300x195.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-hensu/">【bat】バッチファイルで変数や環境変数の使い方！エラー対処法あり</a>
						<span class="p-blogCard__excerpt">バッチファイルで変数や環境変数を設定するやり方を教えます。 その他にも変数に関わる事をご紹介します。 この記事でわかる事 変数を指定する時の注意点など 計算結果&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p>「echo_test」フォルダ配下には「echo.bat」があります。</p>


<div class="wp-block-image is-style-border">
<figure class="aligncenter size-full"><img decoding="async" width="639" height="278" src="https://sugublog.org/wp-content/uploads/2024/02/bat実行3_server_bat_echo.png" alt="batを実行する" class="wp-image-6302" srcset="https://sugublog.org/wp-content/uploads/2024/02/bat実行3_server_bat_echo.png 639w, https://sugublog.org/wp-content/uploads/2024/02/bat実行3_server_bat_echo-300x131.png 300w" sizes="(max-width: 639px) 100vw, 639px" /></figure>
</div>


<p>「echo.bat」の内容は以下です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain" data-file="echo.bat"><code>@echo off
call ..\def.bat
echo %name%
pause</code></pre></div>



<p>この「echo.bat」はひとつ前のフォルダにある「def.bat」の変数「name」を参照しています。</p>



<p>他のファイルの変数の値「Windows server2016」の文字列を参照してechoで表示するbatファイルです。</p>



<p>この「echo.bat」を<span class="swl-bg-color has-swl-deep-03-background-color">サーバー上で実行</span>して見ます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>Windows server2016
続行するには何かキーを押してください . . .</code></pre></div>



<p><span class="swl-marker mark_green">実行されています。</span></p>



<p>今度は<span class="swl-bg-color has-swl-deep-01-background-color">端末側でサーバーのbatファイルを実行</span>してみます。</p>


<div class="wp-block-image is-style-border">
<figure class="aligncenter size-full"><img decoding="async" width="502" height="126" src="https://sugublog.org/wp-content/uploads/2024/02/bat実行4_PC_bat_echo.png" alt="batを実行する" class="wp-image-6303" srcset="https://sugublog.org/wp-content/uploads/2024/02/bat実行4_PC_bat_echo.png 502w, https://sugublog.org/wp-content/uploads/2024/02/bat実行4_PC_bat_echo-300x75.png 300w" sizes="(max-width: 502px) 100vw, 502px" /></figure>
</div>


<p>エクスプローラーのURL欄にサーバーの共有フォルダのパスをいれてアクセスしています。</p>


<div class="wp-block-image is-style-border">
<figure class="aligncenter size-full"><img decoding="async" width="621" height="195" src="https://sugublog.org/wp-content/uploads/2024/02/bat実行5_PC_bat_echo_error.png" alt="batを実行する" class="wp-image-6304" srcset="https://sugublog.org/wp-content/uploads/2024/02/bat実行5_PC_bat_echo_error.png 621w, https://sugublog.org/wp-content/uploads/2024/02/bat実行5_PC_bat_echo_error-300x94.png 300w" sizes="(max-width: 621px) 100vw, 621px" /></figure>
</div>


<p class="is-style-big_icon_caution">端末では実行してもエラーになり、思うような結果になりませんでした。</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ファイルが実行できない時の対処法</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="682" src="https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-1024x682.jpg" alt="batファイル実行できない時の対処法" class="wp-image-4502" srcset="https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-1024x682.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-300x200.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-768x511.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p><span class="swl-marker mark_yellow"><strong>サーバー上のbatファイル</strong>で、<strong>他のファイルを参照</strong>しているような内容のbatファイルだと<strong>実行できません</strong>。</span></p>



<p class="has-border -border02">対処法としてはサーバーにリモートデスクトップ接続して、直接実行する事です。</p>



<p>サーバー上のbatファイルは、サーバー上で直接実行すると覚えておきましょう！</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sugublog.org/bat-execution/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
