小编kar*_*r41的帖子

创建 python 脚本来编译和运行 c++ 文件

我一直在编写一个简单的 python 脚本来编译和运行给定的 .cpp 文件。

我已经让它按预期工作,但我希望能够在 .cpp 文件的编译产生错误或警告时停止脚本,而不是继续执行 .exe 文件。

# run_cpp.py
# Script that compiles and executes a .cpp file
# Usage:
# python run_cpp.py -i <filename> (without .cpp extension)

import sys, os, getopt

def main(argv):
    cpp_file = ''
    exe_file = ''
    try:
        opts, args = getopt.getopt(argv, "hi:",["help",'ifile='])
    except getopt.GetoptError as err:
        # print help information and exit
        print(err)      
        usage()
        sys.exit(2)
    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-i", "--ifile"):
            cpp_file …
Run Code Online (Sandbox Code Playgroud)

windows bash compilation python-3.x

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

bash ×1

compilation ×1

python-3.x ×1

windows ×1