【发布时间】:2019-04-13 17:13:27
【问题描述】:
这可能吗?
这是一个例子:
#include <stdio.h>
#include <stdlib.h>
char testString[]="blunt"
#define shellscript1 "\
#/bin/bash \n\
printf \"\nHi! The passed value is: $1\n\" \n\
"
int main(){
system(shellscript1);
return 0;
}
现在我想将一个值从testString 传递给shellscript1,而不必保留制作一个临时的外部脚本。
我一直在抨击我的头,但我不知道该怎么做。有人有什么想法吗?
【问题讨论】:
-
你想把 testString 作为参数传递给 shellscript1 吗?
-
您可以使用
putenv并使用该变量而不是 $1 调用脚本 -
你可以只
popen("bash")并提供你的 bash 命令。 -
当你可以把它喂给蟒蛇时,不要再敲你的头了:)