Reputation: 2144
I need to create a symbolic link of a js file. I tried the below:
x = "C:/Program Files/apache-tomcat-7.0.41/webapps/analytics/js/analyticsController.js"
y = "c:/svn/web/src/main/webapp/analytics/js/analyticsController.js"
exec ("mklink #{x} #{y}")
and also system ("mklink #{x} #{y}")
neither of them created symbolic link.
I was able to run commands like system ("echo Hello") #prints hello
using ruby script
The mklink does not create the symbolic link. The console did not show any result either.
Upvotes: 1
Views: 1579
Reputation: 696
Ruby 2.3 supports symbolic links on Windows. You can use File.symlink
.
Upvotes: 3
Reputation: 934
The mklink command on Windows (7 and above) requires a parameter for the type of link to make. Symbolic links on windows are the "shortcuts" that normal users can make themselves. What you likely are intending to create is a hard link, or "junction point". The command to create a junction point is:
mklink /J <destination> <source>
So, in ruby, this is:
exec ("mklink /J #{x} #{y}")
Apparently the cmd.exe shell only has access to mklink, so it has to be invoked first.
exec ("cmd.exe /c \"mklink /J #{x} #{y}\"")
One final note (of caution). Making links on Windows requires full administrator access.
Upvotes: 1