Issue
Say I have a file that I want to turn into an executable in Elixir while preserving its original permissions. How would I go about that? Do I use File.chmod
(and if so, how?) or System.cmd
?
Solution
You may not be able to use File.chmod
as it expects non-negative integer as way to express permissions, e.g. 755, 666, etc. This hence, requires one to set all permissions and may not allow to retain existing permissions.
File.chmod("file.sh", 755)
Hence, System.cmd
seems like more apt way, as it executes the chmod
system command.
{msg, result} = System.cmd "chmod", ["+x", filename], cd: pathname
#=> {"", 0}
result
value of 0
indicates that command was successful.
Answered By - Wand Maker Answer Checked By - Candace Johnson (WPSolving Volunteer)