在我的例子中,应用程序是OpenFoam,但这种情况也发生在其他Linux程序中.
我有一个py脚本(run_test. py)用Windows VS Code编写:
import subprocess
command = "wsl python3 /mnt/wslg/distro/home/j/test.py"
subprocess.Popen(command, shell=True)
运行另一个脚本py(test.py),在我的WSL中用Linux VS Code编写:
import subprocess
command = "cd $FOAM_RUN/airfopt && foamRun"
process=subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
if output:
print("Output:", output.decode())
if error:
print("Error:", error.decode())
当我通过Linux VS Code启动www.example.com时,一切都工作正常,但是当我运行"run_test. py"时,我得到了错误/bin/sh: 1: cd: can't cd to /airfopt
相反,如果我写完整路径/mnt/wslg/distro/root/OpenFOAM/root-11/run/airfopt
,新的错误是/bin/sh: 1: foamRun: not found
.
我认为因为run_www.example.com在Windows环境下运行test.py,而不是Linux环境下运行. 我想从run_test. py运行www.example.com,但在Linux环境下运行.
运行www.example.com文件也会出现同样的错误.
这是我第一次使用WSL,因为我需要OpenFoam Linux(不是blueCFD等)并将其连接到Windows Python脚本. 我在Google上搜索,这里…我还问了chatgpt,但没有得到一个好的答案.
感谢任何人谁可以帮助我!