【问题标题】:Error using wget in c++在 c++ 中使用 wget 时出错
【发布时间】: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++ 程序时

标签: c++ wget


【解决方案1】:

如果 Visual Studio 确实在路径中并且无法正常工作,它可能会以某种方式覆盖您的正常路径。

只需手动输入完整路径:

system("c:/path/wget ...");

【讨论】:

  • 您能详细说明一下吗?我不知道那是什么意思。我应该指向 wget 的 bin 目录吗?另外,我在 Windows 机器上
  • 是的,就是这样。我把完整路径目录 C:/GnuWin32/bin/wget 和它的工作谢谢!
【解决方案2】:

wget 需要在您的PATH 环境变量的目录列表中拥有其目录。

由于您使用的是 Windows,因此您必须修改您的用户配置。我已经多年没有使用 windows,所以我不再记得它在哪里了。

【讨论】:

  • 如果我进入开始菜单并进入 cmd 并使用 wget 命令,它可以正常工作,但是当我在 c++ 中的 system() 函数中运行该命令时,它就不起作用了。
  • 使用 getenv 查看操作系统给你的应用程序的环境:en.cppreference.com/w/cpp/utility/program/getenv 它可能与其他程序的环境无关。
猜你喜欢
  • 2014-08-25
  • 1970-01-01
  • 2015-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多