Here's a hacky way, probably this is the wrong way :).
Instead of passing a filename, you can pass a sequence of commands. So in particular, you could do something like
pdflatex "\def\ishandout{1} \input{foo.tex}" And then you can checkwhich defines the value ofmacro ishandout\ishandout (and whether it's definedto be 1) inside fooand then reads foo.tex.tex And then, inside foo.tex, you can check whether \ishandout is defined:
\ifdefined\ishandout \documentclass[handout]{beamer} \else \documentclass{beamer} \fi