Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run an executable that contains a space in path from command line on Windows 10?

Tags:

windows

cmd

space

H:\>"H:\Program Files\R\R-3.4.0beta\bin\R.exe"
'H:\Program' is not recognized as an internal or external command,
operable program or batch file.

H:\>"H:\Progra~1\R\R-3.4.0beta\bin\R.exe"
The system cannot find the path specified.

H:\>H:\Progra~1\R\R-3.4.0beta\bin\R.exe
The system cannot find the path specified.

I tried using "..." and Progra~1 and both are not working on Windows 10.

What I'm doing wrong?

like image 600
kireinasora Avatar asked Apr 20 '17 04:04

kireinasora


3 Answers

The way to do this - and I can't believe I'm just now figuring this out - is to use Windows short names generated for files with non-8dot3 names. To get the path or program name in question, type dir /x <path to program>. It will spit out something like PROGRA~1 for Program Files folder. Of course you have to do that directory by directory, and if you have multiple files/folders with spaces in the name, it's cumbersome. If you want the full path formatted with short names, you can do:

for %I in (*) do echo %~sI 

For example, if the file I want to access is C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\License Terms\License_msodbcsql_ENU.txt, I could type:

for %I in ("C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\License Terms\License_msodbcsql_ENU.txt") do echo %~sI

And what I get back is the much easier C:\PROGRA~1\MICROS~2\CLIENT~1\ODBC\170\LICENS~1\LICENS~1.TXT.

Annoying that you can't query the whole directory path without using a loop, but it is what it is. Good for aliases.

There may be an easier way with powershell, but I'm pretty sure there isn't from the cmd prompt.

like image 151
dgo Avatar answered Nov 12 '22 15:11

dgo


Short answer: Use & 'C:\path with spaces\app.exe'

Explanation: Just type your path into powershell and use TAB for auto completion when you choose any directory containing spaces. Powershell will automatically insert single quotes 'bla bla' and it will also put an & in front which is needed to treat the string as something that should be executed. Continue completing your path like usual.

like image 24
Necktschnagge Avatar answered Nov 12 '22 13:11

Necktschnagge


you must be doing something wrong as the double quotes encapsulates the path to the executable including spaces.

To ensure you are doing it correctly, start typing the path to the command and use TAB after F:\Program until you see the correct path, in your case it will automatically do this

"F:\Program Files"

Use your arrow key to go back behind the end quotation and continue the path and use tab until you have reached.

"H:\Program Files\R\R-3.4.0beta\bin\R.exe"

You can also try and issue it with Start

start "H:\Program Files\R\R-3.4.0beta\bin\R.exe"

If Your cmd windows is open on the actual System drive where "Program Files" are located, you can run this instead of adding the drive letter as well:

".\Program Files\R\R-3.4.0beta\bin\R.exe"

Or add it to your environment variables with the path, then it should execute with just:

R.exe
like image 25
Gerhard Avatar answered Nov 12 '22 14:11

Gerhard