Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Windows cmd, how do I run an executable in the current directory (instead of one with the same name in %PATH%) without referring to the full path? [closed]

I'm trying to run an executable foobar from a directory, but Windows also happens to have an executable (or command) named foobar. In UNIX, I'd just write

./foobar

but Windows cmd doesn't seem to understand that. Given that I don't want to add this directory to my %PATH%, is there another way to run the current directory's foobar without typing the path explicitly?

like image 631
slackwing Avatar asked May 04 '14 11:05

slackwing


People also ask

How do you change the current path of the directory in the command line?

To change current working directory under the current drive, use command " cd new-path " (change directory).

How do I run an exe from command line arguments?

Every executable accepts different arguments and interprets them in different ways. For example, entering C:\abc.exe /W /F on a command line would run a program called abc.exe and pass two command line arguments to it: /W and /F.

How do I run an executable from a command prompt in Windows?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.


1 Answers

Windows always looks in the current directory first before searching the path. If you are trying to run a command from a program, try "cd"ing to the directory first like so:

copy con run_foobar.bat
cd c:\myfoobardirectory
foobar
"<CTRL> + Z" 

A special case is if you're trying to execute a file that matches the name of an internal command of cmd.exe, such as 'date', in this case, the internal 'date' command will be executed even if you have a local 'date.exe' executable file in the current directory.

You can force the executaion of the local program file by typing the full name 'date.exe' in the current directory, this will override the internal 'date' command.

Notice also that in PowerShell, the behavior is different to Cmd shell, so even if you type in PowerShell in the local directory a command like 'java' or 'java.exe', then the path command will be executed even if there is a local file with the same name. To force the execution of the local file, we would use the linux style './java' or './java.exe'.

like image 52
paul Avatar answered Nov 15 '22 22:11

paul