前にやろうとして諦めた
pythonだと簡単

try:
  str_sjis = str.encode("CP932")
except UnicodeEncodeError:
  print str.encode("utf-8")