如何在Python中执行C程序? [英] How to execute a C program in Python?

查看:153
本文介绍了如何在Python中执行C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Python中编写一个程序,它以C程序作为输入,针对测试用例执行它,也作为输入并打印每个测试用例的输出。我正在使用Windows。

I want to write a program in Python which takes a C program as input, executes it against the test cases which are also as inputs and print the output for each test case. I am using Windows.

推荐答案

请参阅:

https://docs.python.org/2/library/subprocess.html [ ^ ],

http://stackoverflow.com/questions/880918/how-to-redirect-the-output-of-exe-to-a -file-in-python [ ^ ]。



但是,在大多数情况下,启动和使用外部进程,是一个非常糟糕,非常有限的方法。您几乎无法控制生成过程,因此这种方法主要限于仅使用控制台的应用程序从命令行获取输入并将输出放在标准控制台或某些文件中。更好的方法是使用Python应用程序的库(DLL)。如何做到这取决于特定的Python实现;一些提供与本机DLL的互操作性,一些使用.NET程序集...



-SA
Please see:
https://docs.python.org/2/library/subprocess.html[^],
http://stackoverflow.com/questions/880918/how-to-redirect-the-output-of-exe-to-a-file-in-python[^].

However, starting and using of external process, in most cases, is a pretty bad, very limited approach. You get almost no control over the spawn process, so this approach is mostly limited to console-only application taking input from a command line and putting the output in a standard console, or some files. Much better approach would be using the library (DLL) by a Python application. How to do it depends on the particular Python implementation; some provide interoperability with native DLLs, some work with .NET assemblies…

—SA


这篇关于如何在Python中执行C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆