Skip to content Skip to sidebar Skip to footer

Run Python Script With Arguments In Another Python Script

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

Solution 1:

Use 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"])

Post a Comment for "Run Python Script With Arguments In Another Python Script"