Or, to maintain security,
sudo might be the solution. You could also look into
Expect although this will be less secure as passwords may have to be hard coded.
I'd personally say never hard code passwords into applications, as not only is this a huge security hole, but when the su target changes their password, the application then requires maintenance.
Cheers
ZB