anchor.diff:  %% API
   -export([start_link/0]).
   -export ([run_command/1, run_command/2, check_command/1]).
  --export ([collect_output/2]).
  +-export ([collect_output/2, collect_port/2]).
   
   %% gen_server callbacks
   -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
  
positive.code: % Quick helper for running commands
  run_command(Cmd) -> gen_server:call(server_location(), {run_command, Cmd}).
  check_command(Cmd) -> 
  	Command = lists:flatten(io_lib:format("sh ~s", [Cmd])),
  	gen_server:call(server_location(), {check_command, Command}).
  
  % Run the command, start up the 
  run_command(Cmd, State) ->
  	Command = lists:flatten(io_lib:format("sh ~s", [Cmd])),
  	Port = erlang:open_port({spawn, Command}, [stream, exit_status, stderr_to_stdout]),
  	Pid = spawn(fun() -> collect_output(Port, []) end),
  	AtomCommand = erlang:list_to_atom(Command),
  	?TRACE("storing into state", [AtomCommand, Port, Pid]),
  	NewState = State#state{processes = ?DICT:store(Command, [Port, Pid], State#state.processes)},
  	{ok, NewState}.
  
  collect_output(Port, Acc) ->
  		receive
  			{Port, {data, Data}} ->
  				collect_output(Port, [Data | Acc]);
  			{Port, {exit_status, 0}} ->
  				catch erlang:port_close(Port),
  				lists:flatten(lists:reverse(Acc));
  			{Port, {exit_status, _}} ->
  				catch erlang:port_close(Port),
  				Output = lists:flatten(lists:reverse(Acc)),	
  				{error, Output};
  			_ ->
  				collect_output(Port, Acc)				
  	end.
  
  server_location() -> global:whereis_name(?SERVER).
negative.code: %% Description: Initiates the server
  %%--------------------------------------------------------------------
  init([]) ->
  	% process_flag(trap_exit, true),
    {ok, #state{
  		processes = ?DICT:new()
  	}}.
  