Error using wget in c++ - c++

I downloaded wget from gnuwin32 and I am trying to run the command in a c++ program using the system() function. I am using visual studio 2012 on a windows OS as my compiler. wget runs on the command line but does not run when I put it in the system function. My error is " 'wget' is not recognized as an internal or external command,operable program or batch file"
Here is my code:
#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;
}

Visual Studio is probably overriding your normal path somehow if it really is in the path and not working.
Just put the full path in manually:
system("c:/path/wget ...");

wget needs have its directory in the list of directories in your PATH environment variable.
Since you are using Windows, you'll have to modify it your user configuration. It has been years since I have used windows, so I no longer recall exactly where it is.

Related

Using "string" header file gives error in c++ on Windows 10

So I recently upgraded Windows 8.1 to Windows 10. I didn't faced this type of error before but when I program in c++ and include "string" header file then it pops out an error when executing though compiling does not give any error. I tried using "cstring" and update Microsoft Visual C++ Redistributable but no change. If I don't use "string" header file then it will not produce any error.
Here is test.cpp
#include <iostream>
#include <string>
using namespace std;
int main(){
string text = "Hello World!";
cout << text;
return 0;
}
On compiling it does not give error
g++ test.cpp -o test.exe
But when I tried to execute via console it doesn't print anything.
And when I tried to execute by double clicking "test.exe" then it showed me this
Finally I found what causes this error.
There was a faulty app which is set in my system path variable containing a faulty libstdc++-6.dll which causes this error. I remove the path from th system path variable and now everything working fine.

C++ "system(command)" not working on NetBeans / Windows

I am working on a C++ project using CodeBlocks on Windows but then decided to switch to NetBeans IDE 8.2.
Within my project, I am calling another executable file with some passed parameters (I run the other .exe with suitable parameters then I take the output of it to use in my main project), and it used to work on CodeBlocks but not on NetBeans.
The code is the following:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <cstdlib>
#include <string.h>
#include <sstream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "My_Constants.h"
#include "Data.h"
#include "Parameters.h"
#include "Pattern.h"
#include "Squish.h"
#include "Deserializer.h"
#include "Automatic_Run.h"
using namespace std;
int main()
{
Parameters parameters;
parameters.mode = SQUISH;
Automatic_Run runner;
string inputname;
//--------------------------------User Input-------------------------------------
cout << "enter input file name \n";
getline(cin, inputname);
parameters.inputFileName.assign(inputname);
cout<<"=============================================================================\n";
//--------------------------------Running SQUISH/first call--------------------------
cout<<"Running SQUISH - first call\n";
char command[1000]="";
string passedParameters = " -i "+parameters.inputFileName +" -f "+ "t";
strcat(command,"C:\\Users\\Administrator\\Documents\\CodeBlocksProjects\\TestSQUISH\\bin\\Debug\\TestSQUISH.exe ");
strcat(command,passedParameters.c_str());
int result = system(command);
// the rest of the code(not relevant to the problem)
return 0;
}
On CodeBlocks, it used to work perfectly and give me the output as a file in the path of my main project (the one I am calling TestSQUISH from). However, now on NetBeans, I am getting the following error:
sh: C:UsersAdministratorDocumentsCodeBlocksProjectsTestSQUISHbinDebugTestSQUISH.exe: command not found
I checked the terminal of NetBeans to get an idea of what is happening (assuming it might be related) and I noticed that I have to change the path first, then run the executable using:
./ TestSQUISH.exe (+parameters)
However, that also didn't work for my project.
Can anyone please suggest a solution or tell me how I can make NetBeans run the command on a Windows terminal as CodeBlocks used to do?
Go to the project settings and set the project path for execution to be the folder where the other application is.
OR
Set the system path to include that folder.
Thanks to the comment of #Yksisarvinen, I was able to solve the problem.
Noticing that NetBeans uses the shell and not the Windows-style commands and after using the NetBeans own terminal to really get a clear idea of how it translates paths, I was able to run the code successfully using the following:
char command[1000]="";
string passedParameters = " -i "+parameters.inputFileName +" -f "+ "t";
strcat(command, "/cygdrive/c/Users/Administrator/Documents/CodeBlocksProjects/TestSQUISH/bin/Debug/TestSQUISH.exe ");
strcat(command,passedParameters.c_str());
int result = system(command);
Netbeans terminal adds cygdrive to the beginning of the path, and uses c instead of C:.
And in case the executable is in the same directory as your own project then this would be enough:
char command[1000]="";
string passedParameters = " -i "+parameters.inputFileName +" -f "+ "t";
strcat(command ,"./TestSQUISH.exe ");
strcat(command,passedParameters.c_str());
int result = system(command);

Open an additional program with c++ on Mac [XCode]

I want to open an additional program with c++ on XCode.
It is Firefox.
But if I make
Shell Execute("file://localhost/Applications/Firefox.app");
There is an error 'ShellExecute' was not declared in this scope
In other forum there was a clue to include windows.h and shellapi.h
#include <shellapi.h>
#include <windows.h>
but that makes other errors
shellapi.h: No such file or directory
windows.h: No such file or directory
What should I do? I want to open frefox with c++ in XCode on Mac?
Try running this in Terminal to open Firefox:
open -a Firefox http://www.ibm.com
If that does what you want, you need to wrap it in system() like this:
#include <cstdlib>
#include <fstream>
#include <iostream>
int main()
{
std::system("open -a Firefox");
}
ShellExecute() is only available through the Windows API. You don't have a Windows system.
You can simply use the (more portable) system() function, or one of the exec() functions available on POSIX compliant systems.
I tried the same with chrome and I had to set it in inverted commas:
int main() {
system("open -a 'Google Chrome'");
return 0;
}
with the apostrophe it worked!

Run C++ program in Terminal

I'm trying to run this simple C++ code in Sublime Text on Terminal but it's not exactly working...
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}
I'm getting this message instead:
"hello_world2.cpp:1:10: fatal error: 'iostream' file not found"
How can I fix this?
You most probably are missing development headers for your C++ standard library.
You didn't say anything about your environment, but if you were on Windows on Mac you would for sure get these together with your compiler, so let's assume Linux.
You need to install libstdc++-devel package or equivalent (libstdc++-4.8-dev etc.)

MingW environment paths

I am trying to compile a simple program but the MingW C++ compiler cannot find the path. I have two files one is C:\main.cpp the other one is C:\Include\test.h
#include <iostream>
#include "test.h"
using namespace std;
int main()
{
cout << "test" << endl;
getchar();
return 0;
}
I have modified the CPATH, CPLUS_INCLUDE_PATH enviroment vars to include the C:\Include path but it still will not compile with g++ c:\main.cpp -o c:\main.exe
Output from command line.
c:\main.cpp:2:18: fatal error: test.h: No such file or directory
compilation terminated.
Also I used this registry file. Still doesn't work.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"LIBRARY_PATH"="C:\\Include"
"C_INCLUDE_PATH"="C:\\Include"
"CPLUS_INCLUDE_PATH"="C:\\Include"
There's not really enough information here, and storing source files in the root is suspect, but you might try:
g++ -I Include c:\main.cpp -o c:\main.exe
Assuming your cwd is C:\
This plus system restart was needed.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"LIBRARY_PATH"="C:\\Include"
"C_INCLUDE_PATH"="C:\\Include"
"CPLUS_INCLUDE_PATH"="C:\\Include"