Question:

Can exec() function in php execute a batch file?

by  |  earlier

0 LIKES UnLike

i try to use exec function to run my batch file but it's not working.. this how i do it?

<?php

if(isset($_POST['submit']))

{

echo exec('csv/export.bat');

echo "Done!";

} else {

// display the form

?>

<form action="" method="post">

<input type="submit" name="submit" value="DO IT!">

</form>

<?php

}

?>

anyone know how to run batch files in php?

thanks in advance

 Tags:

   Report

1 ANSWERS


  1. Assuming...

    ... you&#039;re running a Windows PC with

    ... Apache

    ... you&#039;re smart enough to NOT have this run in a public setting (because that&#039;s asking for all sorts of trouble) and this is either a test setup or an intranet setup:

    Make sure that the Apache Service uses an account that has write access to wherever the .bat exports to; that the Apache Service is set to &quot;Interact with the desktop&quot;, and make sure that the full path to the .bat file is being specified, *and* that said batch file is placed outside of the web root folder.

    Why not simply use PHP&#039;s string- and fOpen/fWrite functions to generate a CSV?

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.