tags:

views:

61

answers:

2

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?

A: 

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

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

jakar
+1  A: 

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'])
Josh Wright
so suppose there is something called foo.py and foo.cpp . which one should it take ? and how does it compile foo.cpp if you give /usr/bin/foo?
mekasperasky
It doesn't compile anything, it just lets you call an external executable. If you want to compile it, you'll have to call a compiler of some sort. The example I gave would call /usr/bin/foo. If you wanted it to call /usr/bin/foo.py, you'd need to put that in there.
Josh Wright
according to the question that i have asked about how to run a C++ code . Using Popen how am i supposed to do it?
mekasperasky
You compile it with a C++ compiler.
Josh Wright