当前位置: 技术问答>linux和unix
system调用cmd,怎么捕捉错误msg
来源: 互联网 发布时间:2017-03-20
本文导语: sgq@sgq-PC-MY18AEZE4:~/tools$ cat ftpget.c #include main() { int status; //status = system("cat a.txt"); status = system("busybox ftpget -u sgq1 -p sgq123 10.41.181.207 chin.c chin.c"); //...
sgq@sgq-PC-MY18AEZE4:~/tools$ cat ftpget.c
#include
main()
{
int status;
//status = system("cat a.txt");
status = system("busybox ftpget -u sgq1 -p sgq123 10.41.181.207 chin.c chin.c"); //password error
printf("nnnnnstatus = %dnn",status);
printf("1end");
status = system("busybox ftpget -u sgq -p sgq123 10.41.181.207 chin1.c chin1.c"); // file not exist
printf("nnnnnstatus = %dnn",status);
printf("1end");
}
sgq@sgq-PC-MY18AEZE4:~/tools$ ./ftpget
ftpget: unexpected server response to PASS: 530 Login incorrect. //我想把这里的错误捕捉到,有什么办法么?
status = 256
ftpget: unexpected server response to RETR: 550 Failed to open file. //我想把这里的错误捕捉到,有什么办法么?
1end
status = 256
1endsgq@sgq-PC-MY18AEZE4:~/tools$
#include
main()
{
int status;
//status = system("cat a.txt");
status = system("busybox ftpget -u sgq1 -p sgq123 10.41.181.207 chin.c chin.c"); //password error
printf("nnnnnstatus = %dnn",status);
printf("1end");
status = system("busybox ftpget -u sgq -p sgq123 10.41.181.207 chin1.c chin1.c"); // file not exist
printf("nnnnnstatus = %dnn",status);
printf("1end");
}
sgq@sgq-PC-MY18AEZE4:~/tools$ ./ftpget
ftpget: unexpected server response to PASS: 530 Login incorrect. //我想把这里的错误捕捉到,有什么办法么?
status = 256
ftpget: unexpected server response to RETR: 550 Failed to open file. //我想把这里的错误捕捉到,有什么办法么?
1end
status = 256
1endsgq@sgq-PC-MY18AEZE4:~/tools$
|
命令最后加 2>&1 把标准错误定向到标准输出。