SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Running Bat file

    I made a file test.bat all that i need is to run this file when the user press submit

    this is my coed
    PHP Code:
    <?php
    if(isset($_POST['submit']))
    {
    echo 
    exec('test.bat');
    echo 
    "Done!";
    } else {
    // display the form
    ?>
    <form action="" method="post">
    <input type="submit" name="submit" value="DO IT!">
    </form>
    <?php
    }
    ?>
    but it did not work well, can anyone one help me in executing a batch file??

    because when i press submit the explorer shows loading but the file did not work....

    please i need to know how ti fix this problem

  2. #2
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have bit defender and firewall is not activated

    i tried to write the full path but it did not work

    PHP Code:
    <?php
    shell_exec
    ("c:\wamp\www\testimonial\CJohnss.bat") or die ("<br><br>Error in executing  file");


    ?>

    and it shows for me the error message
    i tried to make the permissions 777 in wamp but also it did not

    i think that the problem is in wamp?? right????

    do u have any idea

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    echo "c:\wamp\www\testimonial\CJohnss.bat";

    Not right, huh? Remember, php expands certain escape sequences when you use double quotes. In this case, \t is a tab character. Use single quotes.

    Be aware the current working directory will be that of your php script, as seen by echo getcwd()

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,816
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    A \ inside " needs to be written as \\
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, first off, what does test.bat do? I've found from personal experience with trying to create a custom desktop app that some shell commands just don't work the way you would expect them to in a Win32 environment.

    Secondly, have you just tried the backtick quotes, such as:

    PHP Code:
    echo `test.bat`; 
    There are several ways to execute shell commands with PHP, but most give slightly differing results.
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery


Bookmarks

Posting Permissions

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