Pythonã§shellãå®è¡ãã
Pythonã§ã¯ã§ããªããã®ãã·ã§ã«ã使ã£ã¦å®è¡ãããã¨ããã¨ãã¯ããã¾ãããï¼
Pythonã§ã¯ãshellãå®è¡ããã«ã¯ï¼éããããã¾ãã
- å®è¡å¾ã®å¤ãã»ããå ´å -> commands.getoutput()
- å®è¡ããã ãã§ããå ´å -> os.system()
commands.getoutput()
>>> import commands >>> pwd = commands.getoutput("pwd") >>> print pwd /Users/Alice/
ãã®ããã«ãcommands.getoutput()ã§ã¯å®è¡å¾ã®å¤ãåå¾ãããã¨ãåºæ¥ã¾ãã
åãé ã£ãAnalyzeDirectoryã§ã¯ãããã使ã£ã¦ls -lã³ãã³ããå®è¡ããåãã¡ã¤ã«ã«å¯¾ãã¦ã¢ããã¼ããæ½ãã¦ãã¾ãã
os.system()
>>> import os >>> pwd = os.system("pwd") /Users/Alice >>> print pwd 0
ãã®ããã«ãos.system()ã§ã¯ãå®è¡ããã ãã§ããã®å®è¡ããå¤ãåå¾ãããã¨ã¯åºæ¥ã¾ããã
以ä¸ã§ãã