         Mix.Task.run("release")
         script = Path.join(root, "bin/permanent1")
 
-        open_port(script, ['start'])
+        env = [{"RELEASE_DISTRIBUTION", "name"}, {"RELEASE_NODE", "permanent1@127.0.0.1"}]
+        open_port(script, ['start'], env)
         wait_until_decoded(Path.join(root, "RELEASE_BOOTED"))
-        assert System.cmd(script, ["rpc", "ReleaseTest.hello_world()"]) == {"hello world\n", 0}
-
-        assert {pid, 0} = System.cmd(script, ["pid"])
+
+        assert System.cmd(script, ["rpc", "ReleaseTest.hello_world()"], env: env) ==
+                 {"hello world\n", 0}
+
+        assert {pid, 0} = System.cmd(script, ["pid"], env: env)
         assert pid != "\n"
 
-        assert System.cmd(script, ["stop"]) == {"", 0}
+        assert System.cmd(script, ["stop"], env: env) == {"", 0}
       end)
     end)
   end


        assert wait_until(fn ->
                 File.read!(Path.join(root, "tmp/log/erlang.log.1")) =~
                   "iex(permanent2@#{@hostname})1> "
               end)

        assert System.cmd(script, ["rpc", "ReleaseTest.hello_world()"]) == {"hello world\n", 0}
        assert System.cmd(script, ["stop"]) == {"", 0}
      end)
    end)
  end

  end

  defp open_port(command, args, env \\ []) do
    env = for {k, v} <- env, do: {to_charlist(k), to_charlist(v)}
    Port.open({:spawn_executable, to_charlist(command)}, [:hide, args: args, env: env])
  end

