繁体   English   中英

如何使用 python json 运行可执行文件

[英]how to run an executable with python json

所以我有这个可执行的二进制文件,可以通过终端和 python 运行
使用代码

$`python3 shell_c.py`

其中 python 文件包含

 import subprocess

def executable_shell():
    x=subprocess.run('cd build && ./COSMO/methane_c0.outmol.cosmo', shell=True, capture_output=True)
    print(x)
executable_shell()

其中 COSMO 是我的可执行文件名,“methane_c0.outmol”是动态值,应该与作为扩展名的“.cosmo”一起更改)

所以要从 JSON 文件中获取这些值,我创建了一个带有输入的 JSON 文件

{
    "root_directory": "C:\\Users\\15182\\cosmo theory\\COSMO\\UDbase8",
    "file_name": "methane_c0",
    "file_format": ".cosmo",
    "output1": "N_atoms",
    "output2": "total number of segments"
}

现在剩下的就是将 file_name 和 file_format 的值传递给子进程代码以运行它。 但我不知道如何做 go 。

到目前为止我写的代码是基本的

   import json
        with open ("parameters.json") as file:
            data =json.load(file)
        print(type(data))
        pront(data)

我应该如何 go 以便可以将值传递给 python 文件?

像这样的东西?

import json
import subprocess

with open ("parameters.json") as file:
    data =json.load(file)
dynamic_file_name = data['file_name']+'.outmol'+data['file_format']

def executable_shell():
    x=subprocess.run('cd build && ./COSMO/'+dynamic_file_name, shell=True, capture_output=True)
    print(x)
executable_shell()

暂无
暂无

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

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