mboucher Posted March 19, 2009 Share Posted March 19, 2009 Hi, Is there a way to launch a BAT file with PHP and also pass it parameters based on user input in form boxes? Thanks, Michael Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/ Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 http://php.net/exec Edit: Actually, you might should use shell_exec. Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-788206 Share on other sites More sharing options...
mboucher Posted March 19, 2009 Author Share Posted March 19, 2009 Actually, you might should use shell_exec. Don't think I'm understanding it correctly... <?php $output= shell_exec('test.bat'); echo $output; ?> Should execute test.bat, which simply creates a new folder. But when I open the page, no folder is created. Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-788217 Share on other sites More sharing options...
laffin Posted March 19, 2009 Share Posted March 19, 2009 u may want to be shure its being called <?php echo getcwd() . '/test.bat does ' . (is_file('test.bat)?'':''not ') . 'exist.'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-788223 Share on other sites More sharing options...
mboucher Posted March 19, 2009 Author Share Posted March 19, 2009 u may want to be shure its being called <?php echo getcwd() . '/test.bat does ' . (is_file('test.bat)?'':''not ') . 'exist.'; ?> This just returns a parse error? Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-788225 Share on other sites More sharing options...
laffin Posted March 19, 2009 Share Posted March 19, 2009 Yeah, its top of my head coding. I missed a end quote <?php echo getcwd() . '/test.bat does ' . (is_file('test.bat')?'':''not ') . 'exist.'; ?> if it exists, than ya may want to check safe mode in php.ini and disable it or create an executable dir so php can run external apps Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-788228 Share on other sites More sharing options...
mboucher Posted March 19, 2009 Author Share Posted March 19, 2009 Yeah, its top of my head coding. I missed a end quote <?php echo getcwd() . '/test.bat does ' . (is_file('test.bat')?'':''not ') . 'exist.'; ?> if it exists, than ya may want to check safe mode in php.ini and disable it or create an executable dir so php can run external apps Thanks, but still getting a parse error Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-788230 Share on other sites More sharing options...
mboucher Posted March 19, 2009 Author Share Posted March 19, 2009 if it exists, than ya may want to check safe mode in php.ini and disable it or create an executable dir so php can run external apps safe mode is also off Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-788234 Share on other sites More sharing options...
mboucher Posted March 19, 2009 Author Share Posted March 19, 2009 I've got it to work with.. <?php echo exec('cmd /c test.bat'); ?> But... I am unable to pass parameters to it. If I hard code them in, it works fine, but I am trying to submit them from a form, and it loads filename.php?Parameter1=a&Parameter2=b So my code is: <?php echo exec('cmd /c test.bat $Parameter1 $Parameter2'); ?> But this doesn't seem to work? Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-788252 Share on other sites More sharing options...
laffin Posted March 20, 2009 Share Posted March 20, 2009 question: what is this batch file supposed to accomplish that php can't? u can create a temp batch file within php, if u really needed to. Bypassing the need for sending parameters to a specific batch file. Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-789041 Share on other sites More sharing options...
corbin Posted March 20, 2009 Share Posted March 20, 2009 Or you could just do what ever the batch file does in PHP. As far as I know, there isn't anything a batch file does that PHP can't. By the way, the cmd /c probably wouldn't be needed with shell_exec(). Anyway, it looks like your code is relying on register_globals, and that setting is just straight up evil when set to on. Find a tutorial on $_GET. Short explanation: somepage.php?foo=bar $_GET['foo'] would be "bar" Quote Link to comment https://forums.phpfreaks.com/topic/150092-launch-bat-file-with-parameters/#findComment-789043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.