Hick
Hick

Reputation: 36414

how to pass a command line argument to a c++ file through a python code?

i am compiling a c++ file in python code using this os.system("rc.cpp") and then os.system("./a.out") . I would like to pass a command line argument to the rc file . how do i do it?

Upvotes: 0

Views: 1485

Answers (2)

Josh Wright
Josh Wright

Reputation: 2505

You should be using the subprocess module to call other executables. subprocess.Popen takes a list as it's first argument. The first item in the list is the executable you'd like to call. All list items are the arguments passed to the executable.

from subprocess import Popen
p = Popen(['/usr/bin/foo', 'arg1', 'arg2'])

Upvotes: 1

jakar
jakar

Reputation: 1061

Take a look at scons: http://www.scons.org/

The build configuration files you write for it are python scripts.

Upvotes: 0

Related Questions