简体   繁体   中英

Running python subprocess with ubuntu terminal on windows

Is there a way to run the python module subprocess under Windows, but using the Ubuntu terminal, that is installed in wsl.

My first guess was to promt the ubuntu terminal via the excutable keyword in the function:

subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None, universal_newlines=None, **other_popen_kwargs)

I need the functionality to be able to run OpenFOAM commands with my python programm without immigrating my python code to the Linux system.

EDIT: To clarify my issue a bit further:

I have a GUI with diverse python codes running. From there i need to run OpenFOAM, which is only available under Linux. To overcome that limit, I use Ubuntu (WSL). I would need a WSL shell to run in the background, to execute the linux commands and set up the enviroment needed by OpenFOAM.

Using Ubuntu manually, I start the Terminal and source to the a .bashrc file, where all the enviroment variables are set. From there I can use the OpenFoam commands to run simulations. Those steps would be great to execute from a python code directly.

Hope this helps someone else on that problem:

My workaround for the problem is, that i create a .sh file in my wsl file that i compile with wsl chmod -x filename.sh and then run it with source filename.sh .

Inside my .sh file i load the enviromental variables of OpenFoam by sourcing to the bashrc file of the OpenFoam version that i want to use in my script. From there, I can define each step, that would i normally do in the terminal. (Similar to the Allrun files in the OpenFoam examples)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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