C语言中system调用shell脚本的问题
2010-03-13 09:46
453 查看
在C语言中使用system()语句调用shell脚本时,C语言程序并不会等待system()语句执行完毕尤其在shell脚本有调用bash下命令时并向文件输出时,又无法用刷新标准输出流缓冲区的方式来解决乱序输出的问题.例如
C中部分
for (int i=0;i<5;i++)
{
system("./test.sh");
}
shell中部分
cat /dev/null > test.txt
echo -e "output infomation" >> test.txt
nslookup 8.8.8.8 | grep "name =" >> test.txt #nslookup为解析与逆向解析ip地址的命令会因为网络通信而不能即时得到结果
在有些低版本的linux中
当这部分执行的时候我们在test.txt文件里面看到的结果有可能是
output infomation
output infomation
output infomation
output infomation
output infomation
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
这种情况出现的时候
使用
(echo -e "output infomation" ; nslookup 8.8.8.8) | grep -E 'output information|name ='
就能保证顺序的输出了
C中部分
for (int i=0;i<5;i++)
{
system("./test.sh");
}
shell中部分
cat /dev/null > test.txt
echo -e "output infomation" >> test.txt
nslookup 8.8.8.8 | grep "name =" >> test.txt #nslookup为解析与逆向解析ip地址的命令会因为网络通信而不能即时得到结果
在有些低版本的linux中
当这部分执行的时候我们在test.txt文件里面看到的结果有可能是
output infomation
output infomation
output infomation
output infomation
output infomation
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com
这种情况出现的时候
使用
(echo -e "output infomation" ; nslookup 8.8.8.8) | grep -E 'output information|name ='
就能保证顺序的输出了
相关文章推荐
- c语言中调用shell脚本返回值问题分析
- c语言中调用shell脚本返回值问题分析
- c语言中调用shell脚本返回值问题分析
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)
- shell脚本调用C语言之字符串切分函数——strtok
- java调用shell脚本,解决传参和权限问题
- C程序调用shell脚本共有三种方式:system()、popen()、exec系列函数
- c语言中调用shell脚本
- shell脚本调用python脚本的路径问题
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)的区别
- shell脚本调用java jar包 的问题总结
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)
- java调用并执行shell脚本以及问题总结
- shell脚本中函数调用的返回值,以及退出状态问题
- shell .bashrc中函数在其他脚本无法调用问题
- 使用eval命令解决shell脚本中函数嵌套调用中的参数问题
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)的区别
- 使用Java调用shell脚本时遇到的问题
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)