www.webdeveloper.com
Results 1 to 15 of 15

Thread: execute bat file in PHP

  1. #1
    Join Date
    May 2006
    Posts
    33

    execute bat file in PHP

    please I need advice...

    I have one batch file on the same directory where my PHP + html code is..is there a way to put a button on my web site so that end user can push button and star batch file on server..??

    basicly can I put link or button to execute batch file on the same directory where web site is situated??

    thanks..

  2. #2
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,972
    There probably is a way (someone here will know), but why? What can a batch script do that a PHP script cant?

  3. #3
    Join Date
    May 2006
    Posts
    33
    right...
    but here is Bat file...

    download.ftp
    start.bat


    so it starts one ftp..and than it starts another bat which is for compiling java files..

    so start.ba is:

    javac first1.java
    java.exe first1


    javac second2
    java.exe second2


    copy *.jpg C:\wamp\www\file\pics

    del *.jpg

    so I use java to create some pics..that is why I needed php to execute bat file so it could save some time..any ideas??

  4. #4
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    exec();

  5. #5
    Join Date
    May 2006
    Posts
    33
    <?php
    exec(script.bat);

    ?>

    gives no result...any other ideas??

    Thanks

  6. #6
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239

  7. #7
    Join Date
    May 2006
    Posts
    33
    Thanks Mr Coder it works...but time out is on 30 sec. and also how can I make a button from this:

    <?php
    echo exec('download.ftp');
    echo exec('start.bat');
    ?>

    cheers,

  8. #8
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    http://uk2.php.net/set_time_limit

    As for making a button to do it, I think you mean something like this?

    Code:
    <?php
    if(isset($_POST['submit']))
    {
    echo exec('download.ftp');
    echo exec('start.bat');
    echo "Done!";
    } else {
    // display the form
    ?>
    <form action="" method="post">
    <input type="submit" name="submit" value="DO IT!">
    </form>
    <?php
    }
    ?>
    Last edited by MrCoder; 06-05-2006 at 03:40 PM.

  9. #9
    Join Date
    May 2006
    Posts
    33
    yes exactlly but this would not work...I mean it does not execute .bat file...it seems to alco correct but somehow it would not execute .bat file..

    any ideas?

  10. #10
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    Try it agian, I edited the code.

  11. #11
    Join Date
    May 2006
    Posts
    33
    MrCoder thanks for code it works...but is there a way to put more then 30 sec. in execution time...becouse it takes more then 30 sec fot my bat fiel to execute...can I prolong that time...??

  12. #12
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    set_time_limit(0);

  13. #13
    Join Date
    May 2006
    Posts
    33
    Mr Coder Thank U very much that solved my problem...I later on read about this func.. it can be also changed in php.ini...

    Thanks a lot again..

  14. #14
    Join Date
    Nov 2006
    Posts
    4
    Is there a way to load this bat file and add some parameteres? I would like to add a number of user parameters with whitespace between them.

    How can I do this?

  15. #15
    Join Date
    Mar 2009
    Posts
    1
    Quote Originally Posted by MrCoder View Post
    http://uk2.php.net/set_time_limit

    As for making a button to do it, I think you mean something like this?

    Code:
    <?php
    if(isset($_POST['submit']))
    {
    echo exec('download.ftp');
    echo exec('start.bat');
    echo "Done!";
    } else {
    // display the form
    ?>
    <form action="" method="post">
    <input type="submit" name="submit" value="DO IT!">
    </form>
    <?php
    }
    ?>
    Hi, thanks a lot guys that helped me solve my problem, i am now able to execute bat files but there is one problem. When i push the submit button it redirects to a blank page of my php file. Is there a way to execute my bat files without going to a blank or another page i mean i just pust the sumbit button and it only executes my bat file without effecting my php page.Do i need javascript for this?My bat file is "@echo off
    mode com1:9600,N,8,1 >nul
    echo Q> com1"
    The second question is about having several buttons and executing several bat files , how to write multiple if else coonditions(nested) or i need to use elseif? Please help me ,i'm new in php.
    Thank you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles