9

I feel stupid for asking this, but here goes. In linux/mac, you can run an executable file in the shell, simply by writing its name. Can you do something similar in windows command line?

Example: I am in directory dir. I want to run a file a.exe in dir/subdir without changing directory to subdir, or writing subdir/a.exe. Is this possible?

karlihnos
  • 167
  • 1
  • 16
MyrionSC2
  • 1,105
  • 1
  • 10
  • 15
  • "a.exe was not recognized as an intern or extern command, a program or a batchfile". – MyrionSC2 Feb 17 '15 at 17:18
  • i do have the file. just went to the directory and tried it. works fine. back in the superdirectory it doesn't work. you are right about the frontslash/backslash, but I don't believe it changes anything? – MyrionSC2 Feb 17 '15 at 17:21
  • It would cause errors many places but i can navigate fine with it. "cd dir/subdir" and "cd dir\subdir" gets me the same place. – MyrionSC2 Feb 17 '15 at 17:25
  • But i presume you can execute files from a higher dir in your cmd? – MyrionSC2 Feb 17 '15 at 17:26

3 Answers3

25

You can using one of the following:

  • "subdir/a.exe"
  • subdir\a.exe
Eymen Elkum
  • 2,699
  • 1
  • 15
  • 32
  • OP specifically asks "without changing directory to subdir, or writing subdir/a.exe" and was under the impression that `/` is the Windows path-separator. – Magoo Nov 25 '18 at 05:00
1

You mean you don't want the double-quotes of "subdir/a.exe"? Anyway, if you change to a backslash, it does work; i.e.

subdir\a.exe

user2023370
  • 9,597
  • 5
  • 41
  • 74
-7

It is possible. All you need to do is ensure that the directory in which a.exe resides is included on the path.

Magoo
  • 68,705
  • 7
  • 55
  • 76
  • I'll try to add it to the path then :) thank you – MyrionSC2 Feb 17 '15 at 17:27
  • Works fine. Found out how to add it to the path here: http://stackoverflow.com/questions/9546324/adding-directory-to-path-environment-variable-in-windows. – MyrionSC2 Feb 17 '15 at 17:31
  • Hmm. I'd have googled "Path Editor" myself. All clicky and gooey. – Magoo Feb 17 '15 at 17:41
  • Perhaps it's time to point out to the anonymous downvoters who haven't had the courtesy to explain their downvotes or offer another solution that OP was under the impression that the path separator in WIndows is `/` as it is in Linux AND that OP specifically asks "**without** changing directory to subdir, or **writing subdir/a.exe**". AFAIAA, this is thus the *only* solution (without creating and executing a "shortcut") – Magoo Nov 25 '18 at 04:56
  • Here 5 years later, I would just like to say that Magoo is correct. At the time, I didn't know that path was a thing, and it was indeed what I was looking for. So the downvotes are wrong. – MyrionSC2 Sep 16 '20 at 09:45