spertuit Posted July 10, 2013 Share Posted July 10, 2013 From a web page I need to call a .bat file and have that execute a php script. I need to pass a parameter from php to other php file. So it looks like my first php script would be something like this: system("cmd /c C:test.bat"); My bat file would be something like this: @echo OFF "C:\Program Files (x86)\PHP\v5.4\php-cgi.exe" C:\test.php%* But how can I pass a parameter, like I would call "file.php?event=3"? Quote Link to comment https://forums.phpfreaks.com/topic/280034-call-bat-file-from-php-that-executes-a-php-script-with-parameters/ Share on other sites More sharing options...
spertuit Posted July 10, 2013 Author Share Posted July 10, 2013 So right now I'm trying In my first php script: <?php $par= "3"; $test=`c:\test.bat $par`; echo "<pre>$test</pre>"; ?> Than my test.bat: @echo OFF "C:\Program Files (x86)\PHP\v5.4\php-cgi.exe" C:\inetpub\wwwroot\Lafourche\parish Test.php?event=%1 Quote Link to comment https://forums.phpfreaks.com/topic/280034-call-bat-file-from-php-that-executes-a-php-script-with-parameters/#findComment-1440170 Share on other sites More sharing options...
spertuit Posted July 10, 2013 Author Share Posted July 10, 2013 I seem to have it working, but now I receive "Call to undefined function mysql_connect()", but this is only when the script is called from the batch file. If i call the script form the browser it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/280034-call-bat-file-from-php-that-executes-a-php-script-with-parameters/#findComment-1440184 Share on other sites More sharing options...
spertuit Posted July 10, 2013 Author Share Posted July 10, 2013 Any ideas why argv would not be defined when trying to call the arguement passed from the batch file? Quote Link to comment https://forums.phpfreaks.com/topic/280034-call-bat-file-from-php-that-executes-a-php-script-with-parameters/#findComment-1440190 Share on other sites More sharing options...
AbraCadaver Posted July 10, 2013 Share Posted July 10, 2013 (edited) 1. Why on earth are you calling a batch file just to run another PHP script? 2. Why are you using php-cgi? 3. argv is available to PHP scripts run on the command line (cli). See #2 Edited July 10, 2013 by AbraCadaver Quote Link to comment https://forums.phpfreaks.com/topic/280034-call-bat-file-from-php-that-executes-a-php-script-with-parameters/#findComment-1440191 Share on other sites More sharing options...
spertuit Posted July 10, 2013 Author Share Posted July 10, 2013 Lot of good questions, this seem liked the best way. i have a web portal where companies can log in and enter their employees. There is a process where the employees are created a placard and the placards are than zipped and emailed to the company admin The problem I have is the script that mails the zipped placards to the company admin takes too long to run.(Its over 1,000 admins) The browser gets half done and than a 500 error I thought the best way around this is to create a batch script that runs in the background and maybe it can execute my mail script. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/280034-call-bat-file-from-php-that-executes-a-php-script-with-parameters/#findComment-1440203 Share on other sites More sharing options...
spertuit Posted July 10, 2013 Author Share Posted July 10, 2013 I also tried setting variable equal to argv[1] and it said argv was undefined Quote Link to comment https://forums.phpfreaks.com/topic/280034-call-bat-file-from-php-that-executes-a-php-script-with-parameters/#findComment-1440206 Share on other sites More sharing options...
kicken Posted July 10, 2013 Share Posted July 10, 2013 I thought the best way around this is to create a batch script that runs in the background and maybe it can execute my mail script. exec'ing a batch file like you are will not run the process in the background. PHP will wait for that program to finish executing before it continues with your script. As for ways around a time consuming process, there are various options, such as: 1) Store the info into the database, and then have a scheduled task periodically run a PHP script which checks the database 2) If you use exec, you need to use a program that will really let you run it in the background, such as hstart 3) Create some sort of batching system w/ ajax that will run the task in batchs and provide a status update to the user (they would still have to wait for it to finish though). Quote Link to comment https://forums.phpfreaks.com/topic/280034-call-bat-file-from-php-that-executes-a-php-script-with-parameters/#findComment-1440208 Share on other sites More sharing options...
spertuit Posted July 10, 2013 Author Share Posted July 10, 2013 exec'ing a batch file like you are will not run the process in the background. PHP will wait for that program to finish executing before it continues with your script. As for ways around a time consuming process, there are various options, such as: 1) Store the info into the database, and then have a scheduled task periodically run a PHP script which checks the database 2) If you use exec, you need to use a program that will really let you run it in the background, such as hstart 3) Create some sort of batching system w/ ajax that will run the task in batchs and provide a status update to the user (they would still have to wait for it to finish though). Creating a batching system w/ajax, good suggestion. I think the user can wait for awhile and at least they will get immediate results if the process completes. Ill see what I can come up with. Quote Link to comment https://forums.phpfreaks.com/topic/280034-call-bat-file-from-php-that-executes-a-php-script-with-parameters/#findComment-1440211 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.