Yes you can if you use a here document.
fdisk /dev/sda >/dev/null 2>&1 <<EOF
The here document part, all betweem "EOF and EOF (at the beginning on the line) is given to fdisk and executed by fdisk.
In the above example you create a new partition (n) on /dev/sda, that is primary (p) and partition number 2 (2) with a size of 500Mb (+500M). The result is saved (w).
As you might have noticed the letters/numbers used in the here document are exactly the same as those used when using the fdsik menu.
You can use variables inside the here document if you wish to do so.
Do try this with none-permanent statements first.
Hope this helps.