How to give long paths in java runtime exec method?

272 Views Asked by At

I am trying to use

Runtime.getRuntime().exec("C:\\Program Files\\AutoIt3\\autoit3.exe ./WindowsAuthenticationLogin.au3");

in java

But failing and displaying fail message as

Cannot run program "C:\Program"

Please tell me how can I give correct path to make it work

2

There are 2 best solutions below

1
On BEST ANSWER

The path needs to have escaped quotes around it if it contains spaces. Alternately, for Program Files directory, you can also use this:

Runtime.getRuntime().exec("C:\\Progra~1\\AutoIt3\\autoit3.exe ./WindowsAuthenticationLogin.au3");

0
On

you need to escape the first space with \\

Runtime.getRuntime().exec("C:\\Program\\ Files\\AutoIt3\\autoit3.exe ./WindowsAuthenticationLogin.au3");