|
[Sponsors] |
August 22, 2022, 03:02 |
python subprocess call OF bash script
|
#1 |
Member
Join Date: Apr 2021
Posts: 41
Rep Power: 5 |
Hello,
I am on ubuntu 20.04 Linux with Python 3.8.10 and OpenFOAM is v2112. I believed a simple subprocess.call should allow to run a bash script from a python one. The python script is: Code:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import subprocess subprocess.call("./BashTest") Code:
#!/bin/sh cd "${0%/*}" || exit # Run from this directory . ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions #--------------------------- cd case cleanCase0 echo "BashTest " $(date +%s) > timeLog.txt The python script does not: the txt file is not produced. The cleaning is not done. However if I remove line 3 of the bash script, , which refers to where the openfoam cleanfunctions are located, then the python script produces the txt file. Therefore what could be wrong here ? Many thanks in advance for your help. |
|
October 20, 2022, 09:26 |
|
#2 |
Senior Member
Nico
Join Date: Jan 2022
Location: Germany
Posts: 122
Rep Power: 6 |
Hey, have you ever found a solution? I am stuck with the same problem
|
|
October 26, 2022, 02:51 |
|
#3 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9 |
Can any of you describe more about the error message you got?
I've tried the code and works fine for me. If the problematic line is this one Code:
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions Try this code: Code:
#!/bin/bash cd "${0%/*}" || exit # Run from this directory # Load the environment if not already loaded if [ -z $WM_PROJECT_VERSION ]; then . /opt/OpenFOAM-v2012/etc/bashrc fi . ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions #-------------------------- cleanCase0 || exit echo "BashTest " $(date +%s) > timeLog.txt |
|
October 26, 2022, 03:37 |
|
#4 |
Senior Member
Nico
Join Date: Jan 2022
Location: Germany
Posts: 122
Rep Power: 6 |
Hey Carlos,
this is exactly how i managed to solve the problem a few days ago! |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[OpenFOAM] Paraview python script, creating data using only CLI, saving in csv/excel file | Ash Kot | ParaView | 1 | September 24, 2021 12:23 |
Slurm Bash Script for STAR-CCM+ | Jonathan_DS | Main CFD Forum | 1 | June 6, 2021 15:02 |
[OpenFOAM] Python Script not working Attribute Error | Oguzhan90 | ParaView | 0 | July 5, 2019 04:56 |
[General] Using time in Python script | lingdeer | ParaView | 0 | August 11, 2014 01:57 |
run openfoam with bash script | Gosi | OpenFOAM | 2 | April 11, 2013 09:10 |