CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Problem calling foamDictionary in docker from a python notebook (https://www.cfd-online.com/Forums/openfoam-pre-processing/223346-problem-calling-foamdictionary-docker-python-notebook.html)

Hisham January 7, 2020 07:52

Problem calling foamDictionary in docker from a python notebook
 
Dear Foamers,

I am trying to use the docker image under Windows (1912) and preparing a Jupyter notebook to manage the work. I issue docker commands using subprocesses because I did not have any luck with their Python SDK. Now I am getting familiar with foamDictionary by calling its commands from the notebook. It seems to work except for a special case where I get an error that I cannot decipher.

A Docker command that works from the notebook:
Code:

subprocess.run(docker exec containerName sh -c "\"source /opt/OpenFOAM/setImage_v1912.sh; cd case; foamDictionary system/controlDict -entry endTime -set 100\"")
The one that doesn't:
Code:

subprocess.run(docker exec containerName sh -c "\"source /opt/OpenFOAM/setImage_v1912.sh; cd case; foamDictionary 0/U -entry internalField -set \"uniform (0 0 0 )\"\"")
The foamDictionary command itself runs as expected if given directly inside the container! Calling by subprocess however results in (stderr):

Code:

/opt/OpenFOAM/OpenFOAM-v1912/etc/config.sh/functions: eval: line 67: syntax error near unexpected token `)'
/opt/OpenFOAM/OpenFOAM-v1912/etc/config.sh/functions: eval: line 67: `. /opt/OpenFOAM/OpenFOAM-v1912/etc/config.sh/paraview 0 0 )'

I don't know how and when were these files called!

A clue could be in how Python issues the command to docker which most likely looks like:
Code:

"source /opt/OpenFOAM/setImage_v1912.sh; cd case; foamDictionary 0/U -entry internalField -set "uniform (0 0 0 )""
So how to pass the escape character to a function call to keep the "" instead of turning into "". And for why oh why are these bash scripts called, they are not called (directly!) from inside "foamDictionary.C".

I appreciate helpful pointers and grateful for a solution!

Best regards,
Hisham


All times are GMT -4. The time now is 09:37.