【发布时间】:2019-11-04 17:57:58
【问题描述】:
我正在尝试使用 python 脚本,其中一个变量设置为需要命令行参数的 c 程序 test.c 的输出。下面是我的c程序:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(int argc, char *argv[])
{
int lat;
lat=atoi(argv[1]);
printf("-->%d\n",lat);
}
python程序是:
import subprocess
for lat in range(80,-79,-1):
cmd = '"./a.out" {}'.format(lat)
print "cmd is ",cmd
parm31=subprocess.call(cmd,shell=True)
print "parm is ",parm31
我已经编译了 test.c 来获得 a.out。我的目标是在运行嵌入了 c 程序(test.c 或 a.out)的 python 程序时输出:
parm is -->80
parm is -->79
parm is -->78
...
parm is -->-77
parm is -->-78
不幸的是,我没有得到输出,而是变量的数字分量的其他值和其他一些不需要的输出。如何调整这个程序以获得正确的输出?
【问题讨论】:
-
您还应该发布实际输出。
标签: python c subprocess command-line-arguments