【发布时间】:2014-04-23 13:39:28
【问题描述】:
我从 gnuwin32 下载了 wget,并尝试使用 system() 函数在 c++ 程序中运行该命令。我在 Windows 操作系统上使用 Visual Studio 2012 作为我的编译器。 wget 在命令行上运行,但是当我把它放在系统函数中时没有运行。我的错误是“'wget' 不是内部或外部命令、可运行程序或批处理文件”
这是我的代码:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = string("wget -O test.csv \"http://")+"somewebsitelink\"";
const char *x = str.c_str();
cout << str << endl;
system(x);
system("pause");
return 0;
}
【问题讨论】:
-
你的环境变量中有
wget吗? -
我按照这个网站上的步骤操作:noahcoad.com/post/614/using-wget-on-windows
-
将
wget添加到PATH。您可以使用具有漂亮 GUI 的 PathEditor 来编辑PATH环境变量。 -
或者直接在命令行中输入
set PATH=%PATH%;C:\path\to\wget\ -
我的错误是当我尝试在 Visual Studio 2012 中运行它同时尝试运行 C++ 程序时