Skip to content

Commit

Permalink
Add binary counterparts of cmd and get_env
Browse files Browse the repository at this point in the history
I was also considering adding binary support to put_env, but it would bloat
the code in my opinion. Don't know what's our general policy for using binary vs
charlist
  • Loading branch information
alco committed Apr 5, 2012
1 parent 1e86b31 commit 5f90a6e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/system.ex
Expand Up @@ -68,8 +68,12 @@ defmodule System do
Executes `command` in a command shell of the target OS, captures the standard
output of the command and returns this result as a string.
`command` can be an atom or a charlist
`command` can be an atom, a charlist or a binary.
"""
def cmd(command) when is_binary(command) do
cmd binary_to_list(command)
end

def cmd(command), do: :os.cmd command

@doc """
Expand All @@ -83,6 +87,10 @@ defmodule System do
Returns the Value of the environment variable `varname`, or nil if the
environment variable is undefined.
"""
def get_env(varname) when is_binary(varname) do
get_env binary_to_list(varname)
end

def get_env(varname) do
case :os.getenv(varname) do
match: false
Expand Down

0 comments on commit 5f90a6e

Please sign in to comment.