pycharm调用shell命令
在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
2、调用echo
import subprocess
subprocess.call(["echo 'export PATH=$PATH:/usr/local/nginx/sbin' >> /etc/profile"], shell=True)