gnuplot command not working with system() function in C++ - c++

My gnuplot command is not working in my C++ program. I am trying to run gnuplot command in C++ program like this:
system("gnuplot");
It gives the error:
'gnuplot' is not recognized as an internal or external command. etc.
when I try to run gnuplot in cmd, it works fine.
Any one have idea that why gnuplot command in not working with system() function in C++?

The reason is probably that the environment you execute your C++ program in doesn't tell your operating system to look in the right places to find your gnuplot executable.
Try the full path to the GNU Plot executable, include the file suffix (.exe) if you're on Windows, or make sure to set the PATH environment variable to include the directory in which your gnuplot executable is.

Check whether the path to the gnuplot is in your PATH environment variable. Or alternatively, you can use the absolut path to it when calling system()

Thanks you for answers friends,
I found the solution finally: After editing the environment variable $path, one has to restart the visual studio to get the latest value of environment variable. When I restarted my visual studio, it works.
So when ever you change your any environment variable, just restart visual studio (in case you are using it).
Thanks and kind regards,
Awais

Related

How to clear screen use Eclipse IDE

How to use system clear screen in Eclipse IDE. I use Visual Studio 2017 with command system("cls").
I tried system("clear") but cannot.
system("cls") or system("clear");
'clear' is not recognized as an internal or external command,
operable program or batch file.
system() calls another executable which is provided by your current operating system or a command that's recognized by your default (terminal) shell.
It has nothing to do with your IDE.
There's no generally portable way to clear the screen using c++.
The closest portable way you can get is using something like ncurses.

A command is working in CMD but not working in c++ program using system() function

I'm using Visual Studio 2013
I'm trying to run CMD commands from a C++ program, but some of the commands are working properly in CMD but not working in the C++ program. For example, btdiscovery -s is working in CMD, but not as system("btdiscovery -s") from my C++ program. The error is:
'btdiscovery' is not recognized as internal or external command, operable program or batch file.
Why would this be happening, and how can I fix this?
The first thing to check would be whether the PATH of the hosted (shelled) process contains the executable you're attempting to fire. Alternatively, you could provide a full path to the executable in the launching code.

How do I compile and run a C++ program from Vim?

Whenever I use the :!make % command, vim returns "make is not recognized as an internal or external command, operable program, or batch file." I have tried set makrprg=\"C:\\Program\ Files\ (x86)\\Microsoft\ Visual\ Studio\ 14.0\\VC\\bin\\cl.exe\". However, the same message appears. I believe the error may be in the path I have set, or the format of my statement; however, I am not sure if there is any other underlying cause.
I would greatly appreciate any input. Thanks in advance!
FYI:
I use a Windows 8 computer, and the compiler I typically use is the Microsoft Visual Studio 14.0 compiler.
! is a VIM command that invokes the shell. !make tells the shell to run whatever the shell can fund under the name make. If you want to use VIM's makeprg, you need to use the VIM command :make.
Having said that, setting makeprg to sonething that is not a real make-style program is probably going to work only in the very simplest scenario.
You can run the compiler directly with !cl %. You need to put cl.exe in your PATH and probably set up other environment so that cl can find libraries and include files.
This is because you do not have the make executable installed, which is what vim is looking for. If you're looking to compile on the command line with make, I would recommend switching from the Visual Studio compiler to MinGW
make is a Unix tool, and while it is also available for Windows (in various flavors, native, Cygwin, or MinGW), it is usually not what you will be using together with MS Visual Studio.
It is difficult to be specific, since you told us nothing about the project you are trying to compile, but I will try.
If your project is set up as a Visual Studio solution, you can compile it using devenv:
devenv /build release mysolution.sln
devenv /build release /project mysolution/myproject/myproject.vcxproj
Your project might also be set up for NMake (which is a make-like tool shipping with MSVC):
nmake [target]
The two commands above require the current shell to be properly set up, which can be achieved by starting a "Visual Studio Command Line" from the start menu, or running %VS120COMNTOOLS%\..\..\VC\vcvarsall.bat from whatever shell you happen to work from. (Adjust VS120COMNTOOLS to whatever version of MSVC you are using.)
Or your project might actually be set up using "real" makefiles, in which case I second Levi: It seems like make is not installed, or has not been added to your PATH environment variable.
make [target]

Need assistance with PATH variables

I am compiling C++ programs in Notepad++ and using command prompt to execute and run the programs. Initially I had this problem where the cmd said
"g++" was not a recognized command.
I changed path variable and it was fine. But later when I was started Eclipse, it would not start. I had to change PATH variable again.
So my question is do I have to change the PATH variable every time I switch to running c++ and Eclipse or is there an alternative?
Here is a simple tutorial if you're on windows 7 :
http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx
Once you set PATH variables, make sure to restart your computer. I've been in a similar situation and it was me just getting ahead of myself.

MinGW Distro installation issue

I'm trying to install MinGW distro following the steps here: http://nuwen.net/mingw.html#install
But, when I try to run: gcc --version
at my command line I get the following:
'gcc' is not recognized as an internal or external command,
operable program or batch file.
Why is that?
Thanks.
You need to set up your PATH environment variable so that the command interpreter finds the gcc program.
E.g. (since you’re working in the Windows [cmd.exe] command interpreter)
set path=%path%;%programfiles%\mingw\bin
You have to use the path that applies to your system and your installation of the compiler.
You can set up a more permanent path via the Environment button in the System applet in the Control Panel. You can also do it more low level via the registry (e.g. command regedit). And in other ways.
By the way,
for C++ programming use g++, do not use gcc directly.
At least if you want to avoid trouble. Of course you can do manually what g++ does. But much easier to use g++; that’s what it’s for.
Cheers & hth.,
The command prompt cannot find the program 'gcc'. It's most likely because you have something wrong with the environment variable. If the pathname given in the environment variable is at all incorrect or non-existent (if you have the folder in another place), then command prompt will not be able to find it.