- ã¯ããã«
- 1. ç°å¢å¤æ°ã®åºæ¬
- 2. ç°å¢å¤æ°ã®è¨å®æ¹æ³
- 3. ã¨ã©ã¼ãåé¿ããããã«
- ã¾ã¨ã
ã¯ããã«
ããããã¡ã¤ã«ã¯ãèµ·åæ¹æ³ãç°å¢å¤æ°ã®ãã¹è¨å®ã«ãã£ã¦ãã³ãã³ããæå¾ éãã«åä½ããªããã¨ãããã¾ããç¹ã«ãç°å¢å¤æ°ãæ£ããè¨å®ããã¦ããªãå ´åãã¨ã©ã¼ãçºçããããããã°ã©ã ãæå³éãã«åä½ããªããªããã¨ãããã¾ãã
ãå é¨ã³ãã³ãã¾ãã¯å¤é¨ã³ãã³ããæä½å¯è½ãªããã°ã©ã ã¾ãã¯ããããã¡ã¤ã«ã¨ãã¦èªèããã¦ãã¾ããããã¨ããã¨ã©ã¼ãè¦ããã¨ã¯ããã¾ãããï¼ãã®ã¨ã©ã¼ã¯ãç°å¢å¤æ°ã®ãã¹ãæ£ããè¨å®ããã¦ããªãå ´åã«çºçãã¾ãã
æè¿ãããããã¡ã¤ã«ã®èµ·åæ¹æ³ãå¤æ´ããéã«åæ§ã®ã¨ã©ã¼ã«ç´é¢ãã解決ã«è¦å´ãã¾ãããæ¬è¨äºã§ã¯ãããããã¡ã¤ã«ã§ç°å¢å¤æ°ãè¨å®ããæ¹æ³ãããããæ°¸ç¶çã«é©ç¨ããæ¹æ³ã«ã¤ãã¦è§£èª¬ãã¾ãã
1. ç°å¢å¤æ°ã®åºæ¬
1.1 ç°å¢å¤æ°ã¨ã¯ï¼
ç°å¢å¤æ°ã¯ãOSãã¢ããªã±ã¼ã·ã§ã³ãåä½ããéã«åç
§ããæ
å ±ãä¿æããå¤æ°ã§ãããã¨ãã°ãPATH
å¤æ°ã¯ãã³ãã³ãã©ã¤ã³ã§å®è¡ããããã°ã©ã ãæ¤ç´¢ãããã©ã«ãã®ä¸è¦§ãæå®ãã¾ãã
1.2 ã¦ã¼ã¶ã¼ç°å¢å¤æ°ã¨ã·ã¹ãã ç°å¢å¤æ°ã®éã
ç°å¢å¤æ°ã«ã¯ãã¦ã¼ã¶ã¼ç°å¢å¤æ°ãã¨ãã·ã¹ãã ç°å¢å¤æ°ãã®2種é¡ãããã¾ããããããã®éãã¯ä»¥ä¸ã®éãã§ãã
é ç® | ã¦ã¼ã¶ã¼ç°å¢å¤æ° | ã·ã¹ãã ç°å¢å¤æ° |
---|---|---|
é©ç¨ç¯å² | ç¹å®ã®ã¦ã¼ã¶ã¼ã®ã¿ | å ¨ã¦ã¼ã¶ã¼ |
è¨å®ã®å½±é¿ç¯å² | è¨å®ãè¡ã£ãã¦ã¼ã¶ã¼ã»ãã·ã§ã³å ã®ã¿ | ã·ã¹ãã å ¨ä½ã§æå¹ |
管çè 権éã®å¿ è¦æ§ | ä¸è¦ | å¿ è¦ |
ç¨é | åå¥ã®è¨å®ãå¿ è¦ãªã±ã¼ã¹ã«ä¾¿å© | å ±éè¨å®ãã·ã¹ãã å ¨ä½ã§ä½¿ç¨ããå ´å |
- ã¦ã¼ã¶ã¼ç°å¢å¤æ°ã¯ãç¹å®ã®ã¦ã¼ã¶ã¼ã®ã«ã¹ã¿ãã¤ãºã«å©ç¨ããã¾ãã
- ã·ã¹ãã ç°å¢å¤æ°ã¯ããã¹ã¦ã®ã¦ã¼ã¶ã¼ã«å½±é¿ãä¸ãããããã·ã¹ãã å ¨ä½ã§å©ç¨ããè¨å®ã管çããéã«ä½¿ç¨ããã¾ãã
2. ç°å¢å¤æ°ã®è¨å®æ¹æ³
2.1 ä¸æçãªç°å¢å¤æ°ã®è¨å®
ä¸æçã«ç°å¢å¤æ°ãè¨å®ããã«ã¯ãset
ã³ãã³ãã使ç¨ãã¾ãããã®æ¹æ³ã§è¨å®ããç°å¢å¤æ°ã¯ãç¾å¨ã®ã³ãã³ãããã³ããã»ãã·ã§ã³å
ã§ã®ã¿æå¹ã§ãã
ä¾: ä¸æçã«ç°å¢å¤æ°ãè¨å®
set MY_VAR=HelloWorld
ä¾: PATHã«è¿½å
set PATH=%PATH%;C:\MyApp\bin
注æç¹
- ä¸æçãªè¨å®ã¯ãã³ãã³ãããã³ãããéããã¨å¤±ããã¾ãã
- ã¹ã¯ãªããå ã§è¨å®ããå ´åã¯ãã»ãã·ã§ã³å ã§ã®ã¿å½±é¿ãã¾ãã
2.2 æ°¸ç¶çãªç°å¢å¤æ°ã®è¨å®
2.2.1 æåã§è¨å®
Windowsã®ç°å¢å¤æ°è¨å®ç»é¢ãéã
[ã¹ã¿ã¼ã] ã¡ãã¥ã¼ã§ãç°å¢å¤æ°ãã¨æ¤ç´¢ãããç°å¢å¤æ°ãç·¨éããé¸æãã¾ããç°å¢å¤æ°ã®ç·¨é
ãç°å¢å¤æ°ãã®ç»é¢ã§å¿ è¦ãªå¤æ°åã¨å¤ã追å ãã¦ãOKããæ¼ãã¾ããPATHã®å ´åã¯ãæ¢åã®å¤æ°ã«å¤ã追å ãã¾ãã
2.2.2 ããããã¡ã¤ã«ã§è¨å®
ããããã¡ã¤ã«ã使ç¨ãã¦æ°¸ç¶çãªç°å¢å¤æ°ãè¨å®ããã«ã¯ãsetx
ã³ãã³ãã使ç¨ãã¾ãã
ä¾: ã¦ã¼ã¶ã¼ç°å¢å¤æ°ã®è¨å®
@echo off setx MY_VAR "HelloWorld"
ä¾: ã·ã¹ãã ç°å¢å¤æ°ã®è¨å®ï¼ç®¡çè 権éãå¿ è¦ï¼
@echo off setx MY_VAR "C:\MyApp\bin" /M
/M
ãªãã·ã§ã³ãæå®ããã¨ãã·ã¹ãã ç°å¢å¤æ°ã¨ãã¦è¨å®ããã¾ãã- è¨å®å¾ãæ°ããã³ãã³ãããã³ããã»ãã·ã§ã³ãéãã¨åæ ããã¾ãã
3. ã¨ã©ã¼ãåé¿ããããã«
ã¹ã¯ãªããå ã§ä¸æçã«è¨å®
ç°å¢ä¾åæ§ãæ¸ãããããã¹ã¯ãªããå ã§ä¸æçã«ç°å¢å¤æ°ãè¨å®ãããã¨ãæ¨å¥¨ãã¾ããset
ã³ãã³ãã使ç¨ãã¦è¨å®ããæ¹ã§ãããæ°¸ç¶çè¨å®ãå¿ è¦ãªå ´åãäºå確èªãè¡ã
æ°¸ç¶çã«ç°å¢å¤æ°ãè¨å®ããéã¯ãå½±é¿ç¯å²ãååã«èæ ®ããå¿ è¦ãããã¾ããã¨ã©ã¼ãã§ãã¯ãå®è£
å¤æ°ãæ£ããè¨å®ããã¦ããããã³ãã³ããå®è¡ããåã«ç¢ºèªãããã¸ãã¯ã追å ãã¦ããã¨å®å¿ã§ãã
@echo off REM ç°å¢å¤æ° MY_VAR ããã§ã㯠set errno=0 if not defined MY_VAR ( set errno=1 echo "MY_VAR ã¯è¨å®ããã¦ãã¾ããã" ) REM errno ã確èªãã¦ã¨ã©ã¼å¦ç if not "%errno%"=="0" ( echo ã¨ã©ã¼ãçºçãã¾ãããã¨ã©ã¼ã³ã¼ã: %errno% exit /b %errno% ) REM æ£å¸¸å¦ç echo "MY_VAR ã¯è¨å®ããã¦ãã¾ã: %MY_VAR%" exit /b 0
ã¾ã¨ã
ç°å¢å¤æ°ã®è¨å®ã¯ãã¹ã¯ãªããã®ç§»æ¤æ§ãå®å®æ§ã«å¤§ããªå½±é¿ãä¸ãã¾ããä¸æçãªè¨å®ã¨æ°¸ç¶çãªè¨å®ã使ãåãã¦ãã¨ã©ã¼ãæªç¶ã«é²ããã¨ãéè¦ã§ããã¾ããã¦ã¼ã¶ã¼ç°å¢å¤æ°ã¨ã·ã¹ãã ç°å¢å¤æ°ã®éããç解ããç¨éã«å¿ããé©åãªè¨å®ãè¡ãã¾ãããã
ãã¡ããããããã®è¨äºã§ãããã²ãã§ãã¯ãã¦ã¿ã¦ãã ããï¼