int errcheck = system(docommand.c_str());
if (errcheck != 0)
{
cerr << "Could not retrieve tarball!" << " Errcheck status (debug): " << errcheck << endl;
return errcheck;
}
以下是完整代码:
#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
umask(0);
mkdir("/tmp/.aget", 0755);
chdir("/tmp/.aget");
for (int i = 1; i < argc; i++)
{
string target(argv[i]);
string docommand("");
string s1("wget -q http://aur.archlinux.org/packages/");
string s2("/");
string s3(".tar.gz");
docommand += s1;
docommand += target;
docommand += s2;
docommand += target;
docommand += s3;
cout << "Downloading AUR tarball for '" << target << "'..." << endl;
int errcheck = system(docommand.c_str());
if (errcheck != 0)
{
cerr << "Could not retrieve tarball!" << " Errcheck status (debug): " << errcheck << endl;
return errcheck;
}
}
for (int i = 1; i < argc; i++)
{
string target(argv[i]);
string docommand("");
string s1("tar xf ");
string s2(".tar.gz");
docommand += s1;
docommand += target;
docommand += s2;
cout << "Extracting '" << target << ".tar.gz'..." << endl;
system(docommand.c_str());
}
for (int i = 1; i < argc; i++)
{
string target(argv[i]);
string docommand("");
chdir("/tmp/.aget");
chdir(target.c_str());
system("makepkg -csim --noconfirm > /dev/null");
}
rmdir("/tmp/.aget");
return 0;
}
答案 0 :(得分:1)
Unix退出状态限制为值0-255,即无符号8位整数的范围。因此,你看不到2048。
有关详细信息,请参阅Exit Status wiki页面。
答案 1 :(得分:0)
我怀疑wget总是返回0.
这是因为http请求的实际错误状态在流中。