/    Sign up×
Community /Pin to ProfileBookmark

PHP code not execute the .bat file, help pls!

Are we able to run a batch file using PHP?

Am trying to transform an .xml file into HTML for browser view, it’s not working please advice me!

Am tried the below options:
—————-

<html>
<head>
<script type=”text/javascript”>
function myfunc(){
<?php
exec(‘trans.bat’);
?>
}
</script>
</head>
<body>
<input type=”button” onclick=”myfunc()” value=”Click!” />
</body>

</html>
—————–

it has simply creating the html-out.html but not performing the required action!

trans.bat
—————–


java -jar “10.16.5.126wwwecmtoolsuploadsaxon9saxon9.jar” “uploadbookinfo.xml” “uploadbookinfo_viewer.xslt” > “uploadhtml-out.html”
—————–

also tries some other options
=====================

<?php
$jarfile=”10.16.5.126wwwecmtoolsuploadsaxon9saxon9.jar”;
$input=”uploadbookinfo.xml”;
$xslt=”uploadbookinfo_viewer.xslt”;
$forward=”>”;
$output=”uploadhtml-out.html”;
$process=`java -jar $jarfile $input $xslt $forward $output`;
echo “<pre>$forward</pre>”;
?>

result is same as above!!

========================
<?php
if(isset($_POST[‘submit’])){
exec(‘trans.bat’);
echo “nDone!”;
} else {
?>
<form action=”” method=”post”>
<input type=”submit” name=”submit” value=”Transform”>
</form>
<?php
}
?>

result is same as above!!

any help???

Please note: When am running the batch file manually it’s working file.

Thanks in Advance,
Thirilog

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@sohguanhJul 06.2010 — Please note: When am running the batch file manually it's working file.

Thanks in Advance,

Thirilog[/QUOTE]


Have you tried to print out the return code when you use exec or the backtick operator ?

If return code is not meaningful message, you can try a few options below.

  • 1. try put in the full path to your trans.bat say /home/abc/trans.bat


  • 2. try to see the file permission given to trans.bat and compare to the uid that is executing the PHP code. The uid used to execute the PHP code may not have been given the correct execute/read/write permission to trans.bat
  • Copy linkTweet thisAlerts:
    @criterion9Jul 06.2010 — 
    Am trying to transform an .xml file into HTML for browser view
    [/quote]

    Have you looked into xslt?
    Copy linkTweet thisAlerts:
    @ThirilogauthorJul 07.2010 — Hi All, thanks to all...

    I have tried all your suggestions and finally get through by triggering the <?php

    exec('trans.bat');

    ?> via JS! Thanks again.

    For your kind reference am sharing the code below:

    <script type="text/javascript">

    window.onload = init_loader;

    function init_loader (){

    var head = document.getElementsByTagName('input').item(0);

    document.getElementById('loader').onclick = function () {

    var script = document.createElement('script');

    script.setAttribute( 'type', 'text/javascript' );

    script.setAttribute( 'src', 'remote.php?value=my message' );

    head.insertBefore( script, head.firstChild );

    };

    };

    </script>

    </head>

    <body>

    <form action="upload_file.php" method="post" enctype="multipart/form-data">

    <label for="file">Upload the bookinfo.xml : </label>

    <input type="file" name="file" id="file" /><br/><br/>

    <input type="submit" name="submit" value="Upload" />

    <br/>

    <input id="loader" type="button" value="Transform!"/><!--while mouse click triggering the transformation-->

    </form>

    </body>

    </html>


    -----------

    remote.php
    -----------


    <?php

    echo exec('trans.bat');

    ?>
    -----------

    ×

    Success!

    Help @Thirilog spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.28,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...