简体   繁体   中英

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?

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'])

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM