## bash, sed and coreutils, <strike>95</strike> 89 bytes

You can define a function like this

 f(){ n=$[$1-2];yes \ |sed $[$2*n]q|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}

Or in a more readable format:

 f() { 
 n=$(($1-2))
 
 # The next couple of lines create a rectangle of spaces
 # matching the desired size
 yes ' ' |
 head -n$(($2*n)) |
 tr -d '\n' |
 fold -w$n |

 # Add the pipes and dashes
 sed '
 s/^\|$/|/g # Replace first and last character by a pipe
 1! {$!b } # Do nothing if not on first or last line
 s/ /-/g # Add the dashes
 '
 echo
 }


You can now say `f 4 3`:

 |--|
 | |
 |--|

If you care about trailing new-line, add an echo at the end of function.