首页 > 解决方案 > 在 Windows 上从 Python 运行 C 程序

问题描述

我试图按照本教程在 python 中执行 C 程序。该教程提到它仅适用于 linux。让它在 Windows 10 上运行的正确方法是什么?

# Python 3 program to demonstrate subprocess 
# module
  
import subprocess
import os
  
def excuteC():
  
    # store the return code of the c program(return 0)
    # and display the output
    s = subprocess.check_call("gcc HelloWorld.c -o out1;./out1", shell = True)
    print(", return code", s)



#include<stdio.h>
int main()
{
    printf("Hello World from C");
  
    // returning with any other non zero value
    // would result in an exception
    // when called from python
    return 0;
}

标签: cpython-3.xwindowsscipysubprocess

解决方案


推荐阅读