如何通过linux中的subprocess在节点js中运行c程序

我想创build一个应用程序来运行使用MEAN堆栈的C / C ++程序。 我有一个用户界面,可以写程序,节点作为后端,程序可以通过subprocess编译。

只有printf选项的基本c程序已经用下面的命令正确执行了。

程序文件名:test.c

#include<stdio.h> int main(){ printf("hello world"); return 0; } 

节点命令:为了编译文件,我使用了subprocess“exec(”gcc -o test test.c“,fun(){…})”,它创build没有任何扩展名的二进制输出文件(testing)。

为了运行这个二进制文件,我使用了“exec(”./test“,fun(error,stdout,stderr){…}))”,并将输出返回为“hello world”。

但是如果我在程序中使用“scanf”语句,例如:

 #include<stdio.h> int main(){ int a; scanf("%d",&a); printf("The number is", a); return 0; } 

这里运行程序的命令不起作用。 它只是执行程序,我没有得到任何输出。

在这种情况下,我希望节点subprocess等待用户从UI(即:angular度)input“a”值并返回输出。

先谢谢你。