当前位置: 技术问答>一个execl的问题
iis7站长之家
用execl实现重定向
来源: 互联网 发布时间:2016-12-01
本文导语: 实现重定向: #include #include int main(){ execl("/bin/sh","/bin/sh","./reredirect","1 > filere1",NULL); return 0; } reredirect源代码(小写转为大写): #include #include #include int main() { int ch; while((ch = getch...
实现重定向:
reredirect源代码(小写转为大写):
这个有什么问题吗?大家帮忙看看!
#include
#include
int main(){
execl("/bin/sh","/bin/sh","./reredirect","1 > filere1",NULL);
return 0;
}
reredirect源代码(小写转为大写):
#include
#include
#include
int main()
{
int ch;
while((ch = getchar()) != EOF) {
putchar(toupper(ch));
}
exit(0);
}
这个有什么问题吗?大家帮忙看看!
|
execl("/bin/sh","/bin/sh","./reredirect","1 > filere1",NULL);
==> execl("/bin/sh","/bin/sh","-c","./reredirect 1> filere1",NULL);
==> execl("/bin/sh","/bin/sh","-c","./reredirect 1> filere1",NULL);
|
#include
#include
#include
int main(){
int fd = open("filere1", O_WRONLY|O_CREAT, 0660);
dup2(fd, STDOUT_FILENO);
execlp("ls","ls",NULL);
return 0;
}
#include
#include
int main(){
int fd = open("filere1", O_WRONLY|O_CREAT, 0660);
dup2(fd, STDOUT_FILENO);
execlp("ls","ls",NULL);
return 0;
}