cmd.exe ã®å¼æ°ã®æ±ãããã¾ãã«ãã«ãªã¹ã ã£ãã®ã§ã¡ãã£ã¨é å¼µã£ã¦èª¿ã¹ã¦ã¿ãã
æ¬æ¥ãªãããã¯å
¬å¼ã®è³æã«å½ããã®ãæ£ããã¢ããã¼ãã ã¨æããã©ãã©ããã¦ãå
¬å¼ã®è³æãè¦ã¤ãããªãã£ãã®ã§ãè²ã
試ãã¦æ¨æ¸¬ãã¦ã¿ããã¨ã«ã
æççãªè³æã¯è¦ä»ãããã©ãå®å
¨ãããªããä¸å¿URLè²¼ã£ã¦ãããWindows Server 2003 ã®ãã«ãã ãã©ãæãããããªã«å¤ãããªãã¨æãã
コマンド シェルの概要
コマンド リダイレクト演算子を使用する
ãªã®ã§ã以ä¸ã§è¿°ã¹ãå
容ã¯ééããå«ãå¯è½æ§ãããã¾ããã¨ãããæ£ç¢ºãã¯ä¸åä¿è¨¼ãããªãã®ã§ãããããã
æ¤è¨¼æ¹æ³
以ä¸ã®ãããªå¼æ°ããã 表示ããã ãã®ç°¡å㪠C ã®ããã°ã©ã ãç¨æããã仮㫠args.exe ã¨ã§ããã¦ããã
#include <stdio.h> int main(int argc, char const* argv[]) { int i; for (i = 1; i < argc; i++) { printf("%s\n", argv[i]); } return 0; }
ããã¤ã使ã£ã¦ 1 ã¤ãã¤å¼æ°ãä¸ãã¦å®è¡ãã¦ã¯çµæãè¦ã¦ãµããµãããã
çµè«
éä¸ã®ç´ä½æ²æãæ¸ãããã¨æã£ããã©èª°ãèå³ãªãã¨æãã®ã§ãããªãçµè«ãããç§ãªãã«è¾¿ãã¤ããçµè«ãªã®ã§ãæ¬å½ã«ãããªã£ã¦ããã®ãã©ããã¯ç¥ããªãã
ã³ãã³ãã©ã¤ã³ã®è§£é㯠4 ã¤ã®ãã§ã¼ãºã«åãããã
1. ç°å¢å¤æ°ã®å±é
ã¾ãæåã«ãç°å¢å¤æ°ãå±éãããã
- ç°å¢å¤æ°åã % ã§å²ãã¨å±éãããã
- ä¾: %PATH%
- ç°å¢å¤æ°ãåå¨ããªãå ´å㯠% ã®è¡¨è¨ããã®ã¾ã¾æ®ãã空æååã«ãªã£ããã¯ããªãã
- ç°å¢å¤æ°åã¯å¤§æåã¨å°æåã¯åºå¥ããªãã
- ç°å¢å¤æ°åã¯ãã®æ®µéã§å¤æãããã®ã§ãæçµçã«æ¶ããæåãä¸ã«å
¥ãã¦ãããã¨ã§ç¡çç¢çå±éãé²ããã¨ãã§ããã
- ä¾: %^PATH% (^ 㯠ãã§ã¼ãº 2 ã§åé¤ããã)
2. ã³ãã³ãã©ã¤ã³ã®è§£é
次ã«ãã³ãã³ãã©ã¤ã³å
¨ä½ã®è§£éããããå
¨ä½ã¯ãã¤ãããªãã¤ã¬ã¯ããªã©ããããããåä¸ã®ã³ãã³ãã¨ã¯éããªãã
以ä¸ã®ã«ã¼ã«ã«å¾ã£ã¦è§£éãããã
- ^ ã¯ã^ èªèº«ãåãé¤ãã¦æ¬¡ã®æåãé常ã®æåã¨ãã¦æ±ãã
- ã¤ã¾ãã¨ã¹ã±ã¼ãæåã& | < > ( ) % " ^ ãªã©ã®ç¹æ®æåãé常ã®æåã¨ãã¦æ±ãããã«ããã
- ^ èªèº«ã表ãã«ã¯ã¨ã¹ã±ã¼ãã㦠^^ ã¨ããã
- é常ã®æåã«ä»ããå ´åã¯åã« ^ ãåãé¤ãããã
- ããã«ã¯ã©ã¼ãã§å²ã¾ããé¨åã§ã¯ç¹æ®æåã¯ç¡å¹ã«ãªãã
- ããã«ã¯ã©ã¼ãã¯éãããã¦ããå¿ è¦ã¯ãªãã
- è¤æ°ã®çµã¿ãã§ãããã¨ãããã
- å¥ã®è¦æ¹ãããã¨ãããã«ã¯ã©ã¼ãã¯ç¹æ®æåã解éãããã©ããã®ON/OFFãåãæ¿ããã¹ã¤ããã¨èãããã¨ãã§ããã
- ããã«ã¯ã©ã¼ãã®éå§ã® " ã¯ãã®ç´åã§ã¯ã¾ã ç¹æ®æåã¯æå¹ãªã®ã§ ^ ã§ã¨ã¹ã±ã¼ãã§ããããçµäºã® " ã¯ç¹æ®æåã¯ç¡å¹åããã¦ããã®ã§ ^ ãç¡å¹åããã¦ããã¨ã¹ã±ã¼ãã§ããªãã
3. ç¹æ®æåã®å¦ç
ã³ãã³ãã©ã¤ã³ã¯ç¹æ®æåã使ããã¨ã§è¤æ°ã®ã³ãã³ããå«ãããã¨ãã§ããã以ä¸ã®ãã®ã§ 2. ã§ã¨ã¹ã±ã¼ãããã¦ããªãã£ããã®ã¯ç¹æ®æåã¨ãã¦å¦çãããã
- &
- è¤æ°ã®ã³ãã³ããåºåãã1ã¤ç®ã®ã³ãã³ããå®è¡ãããå¾ã«2ã¤ç®ã®ã³ãã³ããå®è¡ãããã
- &&
- 1ã¤ç®ã®ã³ãã³ããå®è¡ããæåããå ´å(çµäºã³ã¼ãã 0 ã®å ´å)ã®ã¿2ã¤ç®ã®ã³ãã³ããå®è¡ããã
- ||
- 1ã¤ç®ã®ã³ãã³ããå®è¡ãã失æããå ´åã®ã¿2ã¤ç®ã®ã³ãã³ããå®è¡ããã
- |
- 1ã¤ç®ã®ã³ãã³ãã®åºåã2ã¤ç®ã®ã³ãã³ãã®å ¥åã¨ãã¦å®è¡ããã
- <
- ã³ãã³ãã®å ¥åããã¡ã¤ã«ããèªã¿åãã
- >
- ã³ãã³ãã®åºåããã¡ã¤ã«ã¸æ¸ãåºãã
- >>
- ã³ãã³ãã®åºåããã¡ã¤ã«ã¸è¿½è¨ããã
- ( )
- è¤æ°ã®ã³ãã³ããã¾ã¨ãããå ¥åºåãã¾ã¨ãã¦ã§ãããå ¥ãåãå¯è½ã
- ( ã¯ã³ãã³ãã®å
é ã«å½ããé¨åã«ããå ´åã®ã¿è§£éãããã
- ã³ãã³ãã®å é ã¨ã¯ã¤ã¾ããã³ãã³ãã©ã¤ã³ã®å é ãã& && | || ã®ç´å¾ã
- ãã以å¤ã®å ´æã§ã¯å¼æ°ã®ä¸é¨ã®é常æåã¨ãã¦æ±ãããã
- å ¥ãåãå¯è½ãªã®ã§ãéãæ¬å¼§ ) ã¯å¯¾å¿ãããã®ãæ¢ãããããã¡ããã¨ã¹ã±ã¼ãããã ) ã¯ç¡è¦ããã
- éãæ¬å¼§ãè¦ä»ãããªãå ´åã¯ç¶ãã¦å ¥åãä¿ãããã
- æãå¾ãªãå ´æã«ç¹æ®æåãæ¥ãå ´åã¯ããã³ãã³ãã®æ§æã誤ã£ã¦ãã¾ãããããã{ç¹æ®æå} ã®ä½¿ãæ¹ã誤ã£ã¦ãã¾ããã({ç¹æ®æå}ã¯å
·ä½çãªç¹æ®æåæå)ã¨è¨ã£ãã¨ã©ã¼ã«ãªãã
- å¤ããã ) ã ã³ãã³ãã®å é ã®ç¹æ®æåãå ¥åºåå ã®ãªããªãã¤ã¬ã¯ãçã
4. åã ã®ã³ãã³ãã®è§£é
ã³ãã³ãã¯ä»¥ä¸ã®ã«ã¼ã«ã«å¾ã£ã¦è¤æ°ã®æååã«åå²ããããæåã®æååãã³ãã³ããæ®ããå¼æ°ã«ãªãã
追è¨:ã³ã³ãã¤ã©ã«ãã£ã¦æåãå¾®å¦ã«éãã¨ãããã¨ãå¤æãããã¯ã©ã®ã¬ã¤ã¤ã¼ãå¦çãã¦ããã®ã ããâ¦ã
äºéã®ããã«ã¯ã©ã¼ãã«ã¤ãã¦ãcl.exe 㨠gcc.exe ã§ã³ã³ãã¤ã«ããå ´åã§æ±ããéã£ãã®ã§è¿½è¨ã
- åºæ¬çã«ã³ãã³ãã¯é£ç¶ãã空ç½ã«ãã£ã¦åå²ãããã
- ããã«ã¯ã©ã¼ãã§å²ã¾ããé¨åã¨ãã®åå¾ã¯é£ç¶ããæååã¨ã¿ãªãããã
- ãã®éãå²ã£ã¦ããããã«ã¯ã©ã¼ãã¯åé¤ãããã
- ããã«ã¯ã©ã¼ãã¯éãããã¦ããå¿ è¦ã¯ãªãã
- ããã«ã¯ã©ã¼ãã®åå¾ã¯ãã¨ããã®ã¯ãããã«ã¯ã©ã¼ãã«ããå²ãã¯ä»»æã®ä½ç½®ããéå§ã§ãããã¨ãæå³ããã
- ä¾: abc" de"f â ãabc defã
- ããã«ã¯ã©ã¼ãä¸ã§äºéã®ããã«ã¯ã©ã¼ã("")ãè¦ã¤ãã£ãå ´åã
- cl.exe ã§ã³ã³ãã¤ã«ããå ´å㯠" ã®æåã«ãªãã
- ä¾: "abc"" def â ãabc" defã
- ä¾: "print(""hello"")" â ãprint("hello")ã
- gcc.exe ã§ã³ã³ãã¤ã«ããå ´åã¯ã¯ã©ã¼ããéãã¤ã¤ " ã®æåã«ãªãã
- ä¾: "abc"" def â ãabc"ããdefã
- ä¾: "print(""hello"")" â ãprint("hello)ã (1çªç®ã® "" ã§ã¯ã©ã¼ããéãããã2çªç®ã® "" ã¯éãã¦ããéããã¯ã©ã¼ãã«ãªãããæ¶ãã)
- cl.exe ã§ã³ã³ãã¤ã«ããå ´å㯠" ã®æåã«ãªãã
- \ ã¯ã
- ããã«ã¯ã©ã¼ãã®å å¤ãåããã" ã®åã« \ ãåç½®ãã㨠" èªèº«ã表ç¾ã§ããã
- \\" ã¨ãã㨠\" ã® \ ãã¨ã¹ã±ã¼ããããã¨ã«ãªãã \" ã«ãªãããã® " ã¯ç¹æ®æåã§ããã
- \\\" ã¨ãã㨠\\ + \" ã«ãªãã \" ã«ãªãããã® " 㯠" æåèªèº«ã§ããã
- 以ä¸ã\ ãå¢ãã度ã«ä¸è¨ã®ãããªã¨ã¹ã±ã¼ããç¹°ãè¿ãã
- \\\\" â \\" (" ã¯ç¹æ®æå)
- \\\\\" â \\" (" ã¯é常æå)
- ä¸è¨ä»¥å¤ã®å ´æã«ãã \ãã¤ã¾ãå¾ã« " ãç¶ããªã \ ã¯ãããã¤éãªã£ã¦ãã¦ããã®æåèªèº«ã«ãªãã
- ä¾: \\server\path â \\server\path (ãã®ã¾ã¾)
注æç¹
ã¯ã¤ã«ãã«ã¼ãã¯ãªã
ãã * ã ? ã§ãã¿ã¼ã³ã«ããããããã¡ã¤ã«ãå¼æ°ã«å±éãããã¨ãããããcmd.exe ã«ã¯ãããã£ãæ©è½ã¯ä¸åãªãã
ããåãã¦ããããã«è¦ããã¨ããããããã¯åã
ã®ã³ãã³ããä¸ã§ç¬èªã«è§£éãã¦ããã
ã·ã§ã«ãã·ã§ããã¨ãã®ä¸ã§åãããã°ã©ã ãè¦å´ããç¾½ç®ã«ãªããæ²ããä¸ã®å¸¸ã
ç¬èªã®è§£éãããããã°ã©ã ããã
ããã°ã©ã ã®ä¸ã«ã¯å®è¡ããã³ãã³ãã®æååãèªã¿åã£ã¦å¼æ°ãç¬èªã«è§£éãããã®ãããã
ãã®å ´åã4. ã®å±éåã®æååãããã°ã©ã ãç´æ¥è§£éããããã£ã¦ã4. ã§è¿°ã¹ãã«ã¼ã«ã¯ä¸åé©ç¨ãããªãã
ä¾ãã° ruby.exe ãªã©ãããã§ãããruby.exe ã¯å¼æ°ã®ã¯ã©ã¼ãã«ã·ã³ã°ã«ã¯ã©ã¼ãã使ããã
>ruby -e 'puts "Hello, world!"'
Hello, world!
éã« cmd.exe çã«ã¯ãã¾ããããã®ãåããªãã£ããããã
>args -e puts" "'Hello," "world!' -e puts 'Hello, world!' >ruby -e puts" "'Hello," "world!' -e:1: syntax error, unexpected tFID, expecting $end
ç¬èªã®è§£éããã®ããããã©æä½éã®äºææ§ã¯æããããï¼
å¼æ°ãã¨ã¹ã±ã¼ãããã«ã¯
以ä¸ã®çµè«ãããä»»æã®æååãå¼æ°ã¨ãã¦ä¸ãããå ´åã¯ä»¥ä¸ã®ããã«ããã
- ç¹æ®æåãå
¨ã¦ ^ ã§ã¨ã¹ã±ã¼ãããã
- & | < > ( ) ^ " %
- % ã¯ã¨ã¹ã±ã¼ããã¦ããã°çµããã® % ã«ããã ^ ãç°å¢å¤æ°ã®å±éãé²ãã§ãããã
- " ã®åã«ããé£ç¶ãã \ ãåæ°ã® \ ã§ã¨ã¹ã±ã¼ãããã
- å
¨ã¦ã® " ã \ ã§ã¨ã¹ã±ã¼ãããã
- " ã¯ãã§ã« ^ ã§ã¨ã¹ã±ã¼ãããã¦ãããããããæ´ã«ã¨ã¹ã±ã¼ããããã¤ã¾ã \^" ã«ãªãã
- å
¨ä½ã ^" ã ^" ã§å²ãã
- åç´ã« "" ã§å²ã㨠^ ãç¡å¹ã«ãªã£ã¦ãã¾ãã
ä¾:
以ä¸ã®æååã1ã¤ã®å¼æ°ã¨ãã¦ä¸ãããã¨ããã¨â¦
puts "Hello, world"
以ä¸ã®ããã«ãªãã
^"puts \^"Hello, world\^"^"
ã¡ãªã¿ã«ç¬èªã®è§£éãããããã°ã©ã ã¯ãã¾ã¨ããªå®è£
ãªãåãã¦ãããã¨æãã解éã®ããããªãã¦ã©ãã«ã§ããªãã®ã§æ£ç´ãªã¨ããå®å
¨ãªå¯¾å¿ã¯ä¸å¯è½ã
ä¾ãã° cmd.exe ã«çµã¿è¾¼ã¿ã® echo ã³ãã³ãã¯ããã«ã¯ã©ã¼ããªã©ãä¸å解éããã«ãã®ã¾ã¾åºåããã
ææ
èªåã§è¨ãã®ããªãã ãã©ãçµæ§ããç·è¡ã£ã¦ãã¨æãã
ã³ãã³ãããã³ãããã«ãªã¹ãªã®ã¯ãå¥ã®ã¬ã¤ã¤ã¼ã§åãæåãå¥ã®æå³ã§ä½¿ã£ã¦ããããããªããã¨æã£ããããã" (ããã«ã¯ã©ã¼ã)ã ã
ãã§ã¼ãº 2 ã¨ãã§ã¼ãº 4 ã§ã¨ã¹ã±ã¼ãæ¹æ³ãéãããããæ··ä¹±ã®å
ã§ã¯ãªãããªã¨ãã¨è¨ããè¨è¨ãã¹ã ãããã
ãã®è¾ºããè¨è¨ããå½æã®æ
å½è
ã¯ä¸ä½ä½ãèãã¦ããã®ããã¯ã£ããè¨ã£ã¦æ®å¿µãããã