I had a script which converts all csdl (xml) documents into JSON documents. The script can be run in command line by giving two arguments such as source folder where csdl files are located and output folder destination where all generated JSON files are to be stored.
我有一个脚本将所有csdl(xml)文档转换为JSON文档。该脚本可以在命令行中运行,方法是给出两个参数,例如csdl文件所在的源文件夹和输出文件夹目标,其中存储所有生成的JSON文件。
The Command line used for this script is
用于此脚本的命令行是
python3 csdl-to-json.py --input <CSDL-Dir> --output <JSON-Dir>
Now I want run this script as part of another python script.
现在我想将此脚本作为另一个python脚本的一部分运行。
My question is how to run csdl-to-json.py
script in another script(schema.py) by passing arguments.
我的问题是如何通过传递参数在另一个脚本(schema.py)中运行csdl-to-json.py脚本。
1 个解决方案
#1
0
Use subprocess.run()
: https://docs.python.org/3.8/library/subprocess.html#subprocess.run
使用subprocess.run():https://docs.python.org/3.8/library/subprocess.html#subprocess.run
import subprocess
subprocess.run(["csdl-to-json.py", "--input", "<CSDL-Dir>", "--output", "<JSON-Dir>"])
Edited, using the following:
编辑,使用以下内容:
subprocess.call(["python3", "/home/sundeep/Desktop/csdl-to-json/script.py", "--input", "/home/sundeep/Desktop/csdl-to-json/metadata", "--output", "/home/sundeep/Desktop/csdl-to-json/json"])
#1
0
Use subprocess.run()
: https://docs.python.org/3.8/library/subprocess.html#subprocess.run
使用subprocess.run():https://docs.python.org/3.8/library/subprocess.html#subprocess.run
import subprocess
subprocess.run(["csdl-to-json.py", "--input", "<CSDL-Dir>", "--output", "<JSON-Dir>"])
Edited, using the following:
编辑,使用以下内容:
subprocess.call(["python3", "/home/sundeep/Desktop/csdl-to-json/script.py", "--input", "/home/sundeep/Desktop/csdl-to-json/metadata", "--output", "/home/sundeep/Desktop/csdl-to-json/json"])