|
藍森林 http://www.lslnet.com 2006年6月6日 10:18
c與shell如何交換或傳遞變量
順便請教c與shell的混合編程 |
c與shell如何交換或傳遞變量
只知道一點點, 不知道有用否:
一個shell script: run
一個C程序: test.c ->; test
1.下一行是run腳本的代碼
./test $1 $2 $3
2. test.c
int main(int argc,char *argv[])
{
printf("output : %s %s %s\n",argv[1],argv[2],argv[3]);
}
3.運行 ./run tom mike james
顯示結果: output : tom mike james |
c與shell如何交換或傳遞變量
在c中可以用system或者exec族調用shell程序 |
c與shell如何交換或傳遞變量
可以利用文件來傳遞一些變量 |
c與shell如何交換或傳遞變量
或者用管道popen...等 |
| |