简体   繁体   English

如何通过 pycharm 运行 bash 脚本?

[英]How to run a bash script through pycharm?

I have the following set of bash commands我有以下一组bash命令

docker pull mcr.microsoft.com/mssql/server:2017-latest
docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=my_password' \
   --name 'sql1' -p 1401:1433 \
   -v "my_space":/opt/project \
   -d mcr.microsoft.com/mssql/server:2017-latest

winpty docker exec -it sql1 bash
mkdir -p /var/opt/mssql/backup
cp my_db /var/opt/mssql/backup/

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "my_password" -i /opt/project/scripts/database_import/sql_script.sql

apt-get update -y
apt-get install python3-pip -y

python3 -m pip install pymssql
python3 -m pip install pandas==0.19.2
python3 -m pip install time
python3 -m pip install sqlalchemy
python3 -m pip install sqlalchemy_utils
cd /opt/project/
python3 scripts/database_import/import_database.py

What this set of commands is essentially doing is that it pulls the mssql server, restores a database, installs some python packages and it runs a python script inside the mssql docker container.这组命令本质上是在拉取 mssql 服务器,恢复数据库,安装一些 python 包,并在 mssql docker 容器内运行 python 脚本。

Is there a way to run this bash script, from pycharm?有没有办法从 pycharm 运行这个bash脚本?

Sure thing.肯定的事。 If you are using the latest version, then Shell Script should be available https://www.jetbrains.com/help/idea/shell-scripts.html So, for example, I have test.sh file:如果您使用的是最新版本,那么 Shell 脚本应该是可用的 https://www.jetbrains.com/help/idea/shell-scripts.ZFC35FDC70D5FC69D269883A822I7A53有test.sh文件: 在此处输入图像描述

I can just click this green run button and PyCharm will run it, or create Run Configuration for it (see the link above).我只需点击这个绿色的运行按钮,PyCharm 就会运行它,或者为它创建运行配置(参见上面的链接)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM