在pycharm中調用shell命令
1、調用普通命令
# -*- coding:UTF-8 -*-
import subprocess
subprocess.call(["ls /home"], shell=True)
#subprocess.call(["cat /root/d.txt | grep hello"], shell=True)
執行結果
ssh://root@192.168.0.75:22/usr/bin/python -u /app/py_code/test3.py
b.sh oracle test
2、調用sed
# -*- coding:UTF-8 -*-
import subprocess
subprocess.call(["cat /home/b.sh"], shell=True)
subprocess.call(["sed -i 's/hi/hello/g' /home/b.sh"], shell=True)
subprocess.call(["cat /home/b.sh"], shell=True)
執行結果
ssh://root@192.168.0.75:22/usr/bin/python -u /app/py_code/test3.py
hi
hello
二、調用echo
import subprocess
subprocess.call(["echo 'export PATH=$PATH:/usr/local/nginx/sbin' >> /etc/profile"], shell=True)