0

I've got an .exe which prompts the user for input at the command line interface for several numerical parameters and then generates data in a .txt. I would like to use Python in order to run the .exe repeatedly with different numerical parameters.

In Python, I've called the executable with:

subprocess.call(["executable.exe"])

How can I run the executable and specify input parameters (note: I am not referring to miscellaneous parameters such as -s, -t, etc but actual numerical parameters which are fed into the .exe)?

Thanks

EDIT: My .exe was created from a .cpp which doubles a integer given by the user when prompted at CLI.

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main() {
    int ExampleNumber;
    cout << "Please enter a number: ";
    cin >> ExampleNumber;
    ExampleNumber = ExampleNumber*2;

    ofstream ExampleFile;
    ExampleFile.open("ExampleFile.txt");
    ExampleFile << ExampleNumber;
    ExampleFile.close();
}

I tried running the .py with the an input of '3' as an example but it does not seem to be working still?

import subprocess

subprocess.call(["Executable.exe", '3'])
Tim
  • 3
  • 4
  • You should make your code change. [This link](http://stackoverflow.com/questions/9497370/making-exe-file-from-python-that-uses-command-line-arguments) may you help. –  Mar 11 '16 at 10:52
  • This isn't what I'm looking for. I'm not looking to create an executable with Python, I'm just trying to run an already existing .exe with different numerical parameters which are specified at the CLI when the .exe is run. – Tim Mar 11 '16 at 10:56
  • 1
    Dont you want to run your code with parameters given at CLI? –  Mar 11 '16 at 11:00
  • Just did of a lot of experimentation and turns out...you're right! Thanks, Aytaç. – Tim Mar 11 '16 at 13:12

1 Answers1

0

You can pass arguments as follows

subprocess.call(["executable.exe", '--parametername1', 'value1', 
 '--parameter2', 'value2'])

Edit: I mentioned this answer when the code was not given. I assumed that program can read parameters from CLI. My answer is valid only if executable.exe can use input arguments from command line which is not the case here.

  • I tried what you have recommended in my edited main post but it does not seem to be working? I am confused as to what '--parametername' and 'value1' should be doing. – Tim Mar 11 '16 at 11:30
  • AFIK subprocess call cannot be used in this case. My answer is valid only if executable.exe can use input arguments from command line which is not the case here. – Ravisankar Balaji Mar 11 '16 at 12:16