oceanocean
oceanocean

Reputation: 1

Execute exe which needs input file in Python

Is there any way to run exe with inputs in Python? For example, there are two files, aaa.exe and bbb.dat. To run the analysis, I need to put those two files on DOS prompt like below. aaa.exe read the bbb.dat file. It there any command or workaround for this? I tried os.system and subprocess but I could not find a solution...

c:\Users\Program\Siimulation\Input> aaa.exe \bbb.dat

os.system("aaa.exe", "bbb.dat")

Upvotes: -1

Views: 52

Answers (1)

Sajid Shaikh
Sajid Shaikh

Reputation: 14

You can o it by argparse. You can mark an argument as required by passing required=True to add_argument.

import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument("foo", ..., required=True)
parser.parse_args()

or you can use "sys"

import sys
len( sys.argv ) > 1

Upvotes: 0

Related Questions