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?
To change current working directory under the current drive, use command " cd new-path " (change directory).
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.
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.
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With