In my folder are these files:
hello.cpp hello.exe hello.ilk hello.pdb
When I try to execute the .exe file within a terminal in VS Code I receive this:
C:\Users\User\Documents\VS_Code> hello.exe
hello.exe : The term 'hello.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ hello.exe
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (hello.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: The command hello.exe was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\hello.exe". See "get-help about_Command_Precedence" for more details.
When I'm running it from the developer prompter from Visual Studio it works.
I think your issue can be solved by just looking at the error suggestion. It says to use .\hello.exe .
Hope this helps :)
Related
I'm simply trying to print out Hello world. I installed minGW, but the code simply won't work. It gives a "can't find path" error, but I have completed everything to download minGW, and the command prompt shows nothing wrong when I typed cd desktop. Additionally, I enabled theVSC to run on the terminal, but it won't work.
I am expecting the code to print Hello world, but this is what it prints out:
cd : Cannot find path 'C:\MinGW\binc\Users\Harold\Desktop\waffle\' because it does not exist.
At line:1 char:1
+ cd "C:/MinGW/binc/Users/Harold/Desktop/waffle/" ; if ($?) { g++ test. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\MinGW\binc\U...Desktop\waffle\:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
I'm trying to set c/c++ environment in my visual studio code. I have installed the mingw and set the environmental variable of the bin folder. However upon running a code in vs code, it shows the following error:
g++ : The term 'g++' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and
try again. At line:1 char:40
cd "e:\vsCodes\Cpp Codes" ; if ($?) { g++ threen1.cpp -o threen1 } ; ...
CategoryInfo : ObjectNotFound: (g++:String) [], CommandNotFound Exception
FullyQualifiedErrorId : CommandNotFoundException
But command prompt shows the following message when I enter g++ --version:
g++ (tdm64-1) 10.3.0 Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
I have tried solving the issue following the answers in this thread.
You are using powershell terminal, If you dont know what powershell is or you dont need powershell, I recommend you to run Command prompt terminal (cmd). It's available in terminal menu here:
In powershell you can verify that g++ in PATH running this command echo $env:path, it's powershell equivalent of echo %PATH%
I created a program that should rename some files
system("rename file.txt file2.txt"); // examples only
did run fine at cmd , but not powershell
rename : The term 'rename' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ rename
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (rename:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
by This article from MS , powershell should use rename-itemHowever , I don't know any "trick" to determine whther programs ran by powershell or cmdA post for determine program's run by which , uses process checking which I find it hard to implement ( they said use wmic.exe , but I don't know how to and further research needed to be )
The conclusion:
How to determine whether my programs runs on powershell or cmd by C++ ?
Is it possible, by knowing the console used ( programmingly ) , my programs could use if-else method to change the command?
Edit: for the time being , My program's method is read file.txt and paste it in file2.txt ( examples only )..Basically like copy and paste to another renamed file and use system("del file.txt");
How to determine whether my programs runs on powershell or cmd by C++
While that is possible, it also irrelevant to your use case, because the shell that launched your program is your program's parent process (to which you cannot submit commands).
Since your program must launch its own shell (child) process in order to execute a shell command, you're free to choose which shell to invoke .
The system() C library function targets the host platform's default shell, which is cmd.exe on Windows (and /bin/sh on Unix-like platforms), so your command - which uses the internal cmd.exe rename command - will work fine, irrespective of whether your program was invoked from PowerShell or cmd.exe.
I feel like this is a very trivial question, I cannot figure out for the life of me what is going on with my VScode.
that the path is correct and try again.
At line:1 char:1
+ make
+ ~~~~
+ CategoryInfo : ObjectNotFound: (make:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: The command make was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\make". See "get-help about_Command_Precedence" for more details.
I am just trying to compile two files together to make them work. They compile and execute seperately, but when I use the 'make' command, in the terminal within VS, it delivers this error.
I believe that my makefile is setup correctly, literally following my professors video on how to do it and it's working properly.
Any pointers??
As the message says: Make command is not found!
Make sure your make command does exist by simply typing make and hitting enter.
if it does not exist install both: build-essentials and make using pip/conda/npm/npx
These are the main rules to make the target work!
I'm learning C++ for the first time (im using microsoft visual studio code) and i'm trying to run my code based on the video im watching. I have exactly what he has in the video but i have an error;
PS C:\Users\Baseb> g++ cpplearning.cpp
g++ : The term 'g++' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify
At line:1 char:1
g++ cpplearning.cpp
+ CategoryInfo : ObjectNotFound: (g++:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException .
I have downloaded minGW and the path i was using is; C:\MinGW\bin . Do you know why I am getting this error code? I typed G++ --version and it shows I do have G++ installed on my computer.
Thank You
If you run g++ from a terminal and it is a Windows terminal (cmd or other), you have to include the g++ binary path in the Windows PATH environment variable.
If you run the compiler from VS then follow the link from #Eljay comment.