Tuesday, October 4, 2022

[SOLVED] Why .\Turorial.exe can run but Tutorial.exe not on PowerShell?

Issue

I'm new for cmake, and try run the cmake example.

Compiling process is all normal, but when I run Tuturial.exe 5 on powershell, got error as follows:

Suggestion [3,General]: The command django-admin 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: ".\django-admin". See "get-help about_Command_Precedence" for more details.

But run .\Tutorial.exe 5, everything is ok.

So I want know why this error happens, and if I want learn more what things should I learn?

Note: run Tuturial.exe 5 on cmd is also normal.


Solution

Say you have a malicious command named foo in the current directory, unbeknownst to you, and you also have the command foo installed on your system. If you tried to run the (system) command foo, it would instead run the malicious program. So, in a nutshell, it is for security reasons, as it protects you from running unintended programs, and this is the reason that PowerShell (and almost all of Linux, as HolyBlackCat pointed out) forces you to use a ./ or .\ in front of your program name.

This is pointed out and explained in this question.



Answered By - cs1349459
Answer Checked By - Pedro (WPSolving Volunteer)