Either set BATCH env variable or use portupgrade/portinstall with -c or -C flags. The latter gathers all the dependencies of a given port and let's you configure them up front, and then the compilation and installation goes without any interruptions.
-c
--config
Run "make config-conditional" before everything for all tasks.
-C
--force-config
Run "make config" before everything for all tasks.