Drupal Form PHP Passthru I will preface my post with saying I'm new to Drupal and feeling the upward learning curve but I am working my way through api.drupal.org and The Definitive Guide to Drupal 7. That being said. Here is what I'm trying to achieve.

1) Have a form collect user input.
2) When that form is submitted pass that data to the PHP passthru command.
3) Return the results preferably real time of that command as it's running. (I will settle for just getting the results right now AJAX can come later)

Where I am at: I have built a custom module to display the form. I believe my submit handler is even working and the script is kicking off. I just can't get the resulted data. Tried using drupal_get_message but nothing seems to happen.

&lt;?php

function my_module_menu() {
$items = array();
$items['ios_upgrade/form'] = array(
'title' =&gt; t('IOS Upgrade'),
'page callback' =&gt; 'ios_upgrade_form',
'access arguments' =&gt; array('access content'),
'description' =&gt; t('IOS Upgrade'),
'type' =&gt; MENU_CALLBACK,
);
return $items;
}

function ios_upgrade_form() {
return drupal_get_form('my_ios_upgrade_form');
}

function my_ios_upgrade_form($form_state) {
$form['ipaddress'] = array(
'#type' =&gt; 'textfield',
'#size' =&gt; 30,
'#title' =&gt; t('IP Address'),
'#required' =&gt; TRUE,
);
$form['username'] = array(
'#type' =&gt; 'textfield',
'#size' =&gt; 30,
'#title' =&gt; t('Username'),
'#required' =&gt; TRUE,
);
$form['password'] = array(
'#type' =&gt; 'password',
'#size' =&gt; 30,
'#title' =&gt; t('Password'),
'#required' =&gt; TRUE,
);
$form['ios'] = array(
'#type' =&gt; 'textfield',
'#size' =&gt; 30,
'#title' =&gt; t('IOS File'),
'#required' =&gt; TRUE,
);
$form['md5'] = array(
'#type' =&gt; 'textfield',
'#size' =&gt; 30,
'#title' =&gt; t('MD5 Hash'),
'#required' =&gt; TRUE,
);
$form['ftp'] = array(
'#type' =&gt; 'textfield',
'#size' =&gt; 30,
'#title' =&gt; t('FTP Server'),
'#required' =&gt; TRUE,
);
$form['submit'] = array(
'#type' =&gt; 'submit',
'#value' =&gt; 'Submit',
'#submit' =&gt; array('sample_form_submit'),
);
return $form;
}
function sample_form_submit($form, &amp;$form_state) {
if (isset($form_state['values']['submit'] ) ) {
$int = 0;
$ip = $form_state['values']['ipaddress'];
$usr = $form_state['values']['username'];
$pwd = $form_state['values']['password'];
$ios = $form_state['values']['ios'];
$md5 = $form_state['values']['md5'];
$ftp = $form_state['values']['ftp'];

$message = passthru("expect scripts/ios-upgrade.exp $int $ip $usr '$pwd' $ios $md5 $ftp  2&gt;&amp;1");

drupal_get_message($message);
}
}


Ideally the user would be redirected to a new page to get this output, which sounds like a multi-step form would be in order. I'm trying to build this one small step at a time though before I add more layers of complexity.

Thank you in advance.
theme('status_messages') will output all of your messages those are pushed using drupal_set_message()

EDIT: 

If you are processing your form via ajax call then you can return the status messages by following code example. Use it in your ajax callback where form is being posted.

$messages = theme('status_messages');
drupal_json_output(array('status' =&gt; 'OK', 'data' =&gt; $messages));